Skip to content

Commit

Permalink
fix MakeFunctionCallable for dealing with public typedef to private…
Browse files Browse the repository at this point in the history
… type
  • Loading branch information
Vipul-Cariappa committed Jan 8, 2025
1 parent c446c3e commit 4cd07ac
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/Interpreter/CppInterOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,12 @@ namespace Cpp {
PrintingPolicy Policy) {
//TODO: Implement cling desugaring from utils::AST
// cling::utils::Transform::GetPartiallyDesugaredType()
QT = QT.getDesugaredType(C);
if (!QT->isTypedefNameType() || QT->isBuiltinType())
QT = QT.getDesugaredType(C);
#if CLANG_VERSION_MAJOR > 16
Policy.SuppressElaboration = true;
#endif
Policy.FullyQualifiedName = true;
QT.getAsStringInternal(type_name, Policy);
}

Expand Down Expand Up @@ -1652,13 +1657,13 @@ namespace Cpp {
return;
} else if (QT->isPointerType()) {
isPointer = true;
QT = cast<clang::PointerType>(QT)->getPointeeType();
QT = cast<clang::PointerType>(QT.getCanonicalType())->getPointeeType();
} else if (QT->isReferenceType()) {
if (QT->isRValueReferenceType())
refType = kRValueReference;
else
refType = kLValueReference;
QT = cast<ReferenceType>(QT)->getPointeeType();
QT = cast<ReferenceType>(QT.getCanonicalType())->getPointeeType();
}
// Fall through for the array type to deal with reference/pointer ro array
// type.
Expand Down Expand Up @@ -1911,7 +1916,7 @@ namespace Cpp {
make_narg_ctor_with_return(FD, N, class_name, buf, indent_level);
return;
}
QualType QT = FD->getReturnType().getCanonicalType();
QualType QT = FD->getReturnType();
if (QT->isVoidType()) {
std::ostringstream typedefbuf;
std::ostringstream callbuf;
Expand Down
50 changes: 50 additions & 0 deletions unittests/CppInterOp/FunctionReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,56 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) {

FCI_Add.Invoke(&result, {args, /*args_size=*/2});
EXPECT_EQ(result, a + b);

// call with pointers
Interp->process(R"(
void set_5(int *out) {
*out = 5;
}
)");

Cpp::TCppScope_t set_5 = Cpp::GetNamed("set_5");
EXPECT_TRUE(set_5);

Cpp::JitCall set_5_f = Cpp::MakeFunctionCallable(set_5);
EXPECT_EQ(set_5_f.getKind(), Cpp::JitCall::kGenericCall);

int* bp = &b;
void* set_5_args[1] = {(void*)&bp};
set_5_f.Invoke(nullptr, {set_5_args, 1});
EXPECT_EQ(b, 5);

#if CLANG_VERSION_MAJOR > 16
// typedef resolution testing
// supported for clang version >16 only
Interp->process(R"(
class TypedefToPrivateClass {
private:
class PC {
public:
int m_val = 4;
};
public:
typedef PC PP;
static PP f() { return PC(); }
};
)");

Cpp::TCppScope_t TypedefToPrivateClass =
Cpp::GetNamed("TypedefToPrivateClass");
EXPECT_TRUE(TypedefToPrivateClass);

Cpp::TCppScope_t f = Cpp::GetNamed("f", TypedefToPrivateClass);
EXPECT_TRUE(f);

Cpp::JitCall FCI_f = Cpp::MakeFunctionCallable(f);
EXPECT_EQ(FCI_f.getKind(), Cpp::JitCall::kGenericCall);

void* res = nullptr;
FCI_f.Invoke(&res, {nullptr, 0});
EXPECT_TRUE(res);
#endif
}

TEST(FunctionReflectionTest, IsConstMethod) {
Expand Down

0 comments on commit 4cd07ac

Please sign in to comment.