Skip to content

Commit 667f38e

Browse files
fix MakeFunctionCallable for dealing with public typedef to private type
1 parent c446c3e commit 667f38e

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

lib/Interpreter/CppInterOp.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,12 @@ namespace Cpp {
16001600
PrintingPolicy Policy) {
16011601
//TODO: Implement cling desugaring from utils::AST
16021602
// cling::utils::Transform::GetPartiallyDesugaredType()
1603-
QT = QT.getDesugaredType(C);
1603+
if (!QT->isTypedefNameType() || QT->isBuiltinType())
1604+
QT = QT.getDesugaredType(C);
1605+
#if CLANG_VERSION_MAJOR > 16
1606+
Policy.SuppressElaboration = true;
1607+
#endif
1608+
Policy.FullyQualifiedName = true;
16041609
QT.getAsStringInternal(type_name, Policy);
16051610
}
16061611

@@ -1652,13 +1657,13 @@ namespace Cpp {
16521657
return;
16531658
} else if (QT->isPointerType()) {
16541659
isPointer = true;
1655-
QT = cast<clang::PointerType>(QT)->getPointeeType();
1660+
QT = cast<clang::PointerType>(QT.getCanonicalType())->getPointeeType();
16561661
} else if (QT->isReferenceType()) {
16571662
if (QT->isRValueReferenceType())
16581663
refType = kRValueReference;
16591664
else
16601665
refType = kLValueReference;
1661-
QT = cast<ReferenceType>(QT)->getPointeeType();
1666+
QT = cast<ReferenceType>(QT.getCanonicalType())->getPointeeType();
16621667
}
16631668
// Fall through for the array type to deal with reference/pointer ro array
16641669
// type.
@@ -1911,7 +1916,7 @@ namespace Cpp {
19111916
make_narg_ctor_with_return(FD, N, class_name, buf, indent_level);
19121917
return;
19131918
}
1914-
QualType QT = FD->getReturnType().getCanonicalType();
1919+
QualType QT = FD->getReturnType();
19151920
if (QT->isVoidType()) {
19161921
std::ostringstream typedefbuf;
19171922
std::ostringstream callbuf;

unittests/CppInterOp/FunctionReflectionTest.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,53 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) {
974974

975975
FCI_Add.Invoke(&result, {args, /*args_size=*/2});
976976
EXPECT_EQ(result, a + b);
977+
978+
// call with pointers
979+
Interp->process(R"(
980+
void set_5(int *out) {
981+
*out = 5;
982+
}
983+
)");
984+
985+
Cpp::TCppScope_t set_5 = Cpp::GetNamed("set_5");
986+
EXPECT_TRUE(set_5);
987+
988+
Cpp::JitCall set_5_f = Cpp::MakeFunctionCallable(set_5);
989+
EXPECT_EQ(set_5_f.getKind(), Cpp::JitCall::kGenericCall);
990+
991+
int* bp = &b;
992+
void* set_5_args[1] = {(void*)&bp};
993+
set_5_f.Invoke(nullptr, {set_5_args, 1});
994+
EXPECT_EQ(b, 5);
995+
996+
// typedef resolution testing
997+
Interp->process(R"(
998+
class TypedefToPrivateClass {
999+
private:
1000+
class PC {
1001+
public:
1002+
int m_val = 4;
1003+
};
1004+
1005+
public:
1006+
typedef PC PP;
1007+
static PP f() { return PC(); }
1008+
};
1009+
)");
1010+
1011+
Cpp::TCppScope_t TypedefToPrivateClass =
1012+
Cpp::GetNamed("TypedefToPrivateClass");
1013+
EXPECT_TRUE(TypedefToPrivateClass);
1014+
1015+
Cpp::TCppScope_t f = Cpp::GetNamed("f", TypedefToPrivateClass);
1016+
EXPECT_TRUE(f);
1017+
1018+
Cpp::JitCall FCI_f = Cpp::MakeFunctionCallable(f);
1019+
EXPECT_EQ(FCI_f.getKind(), Cpp::JitCall::kGenericCall);
1020+
1021+
void* res = nullptr;
1022+
FCI_f.Invoke(&res, {nullptr, 0});
1023+
EXPECT_TRUE(res);
9771024
}
9781025

9791026
TEST(FunctionReflectionTest, IsConstMethod) {

0 commit comments

Comments
 (0)