Skip to content

Commit 2b096c7

Browse files
fix MakeFunctionCallable's codegen when return type is a function pointer
1 parent fc852d5 commit 2b096c7

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/Interpreter/CppInterOp.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,9 @@ namespace Cpp {
16701670
//
16711671
ASTContext& C = FD->getASTContext();
16721672
PrintingPolicy Policy(C.getPrintingPolicy());
1673+
#if CLANG_VERSION_MAJOR > 16
1674+
Policy.SuppressElaboration = true;
1675+
#endif
16731676
refType = kNotReference;
16741677
if (QT->isRecordType() && forArgument) {
16751678
get_type_as_string(QT, type_name, C, Policy);
@@ -1984,18 +1987,22 @@ namespace Cpp {
19841987
EReferenceType refType = kNotReference;
19851988
bool isPointer = false;
19861989

1990+
std::ostringstream typedefbuf;
1991+
std::ostringstream callbuf;
1992+
1993+
collect_type_info(FD, QT, typedefbuf, callbuf, type_name, refType,
1994+
isPointer, indent_level, false);
1995+
1996+
buf << typedefbuf.str();
1997+
19871998
buf << "if (ret) {\n";
19881999
++indent_level;
19892000
{
1990-
std::ostringstream typedefbuf;
1991-
std::ostringstream callbuf;
19922001
//
19932002
// Write the placement part of the placement new.
19942003
//
19952004
indent(callbuf, indent_level);
19962005
callbuf << "new (ret) ";
1997-
collect_type_info(FD, QT, typedefbuf, callbuf, type_name, refType,
1998-
isPointer, indent_level, false);
19992006
//
20002007
// Write the type part of the placement new.
20012008
//

unittests/CppInterOp/FunctionReflectionTest.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,9 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) {
885885
int f3() { return 3; }
886886
887887
extern "C" int f4() { return 4; }
888+
889+
typedef int(*int_func)(void);
890+
int_func f5() { return f3; }
888891
}
889892
)");
890893

@@ -920,6 +923,18 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) {
920923
FCI4.Invoke(&ret4);
921924
EXPECT_EQ(ret4, 4);
922925

926+
#if CLANG_VERSION_MAJOR > 16
927+
Cpp::JitCall FCI5 =
928+
Cpp::MakeFunctionCallable(Cpp::GetNamed("f5", Cpp::GetNamed("NS")));
929+
EXPECT_TRUE(FCI5.getKind() == Cpp::JitCall::kGenericCall);
930+
931+
typedef int (*int_func)();
932+
int_func callback = nullptr;
933+
FCI5.Invoke((void*)&callback);
934+
EXPECT_TRUE(callback);
935+
EXPECT_EQ(callback(), 3);
936+
#endif
937+
923938
// FIXME: Do we need to support private ctors?
924939
Interp->process(R"(
925940
class C {

0 commit comments

Comments
 (0)