Skip to content

Commit 2257e1e

Browse files
fix MakeFunctionCallable for dealing with public typedef to private type
1 parent 8c0cd6d commit 2257e1e

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

lib/Interpreter/CppInterOp.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,10 @@ 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+
Policy.SuppressElaboration = true;
1606+
Policy.FullyQualifiedName = true;
16041607
QT.getAsStringInternal(type_name, Policy);
16051608
}
16061609

@@ -1652,13 +1655,13 @@ namespace Cpp {
16521655
return;
16531656
} else if (QT->isPointerType()) {
16541657
isPointer = true;
1655-
QT = cast<clang::PointerType>(QT)->getPointeeType();
1658+
QT = cast<clang::PointerType>(QT.getCanonicalType())->getPointeeType();
16561659
} else if (QT->isReferenceType()) {
16571660
if (QT->isRValueReferenceType())
16581661
refType = kRValueReference;
16591662
else
16601663
refType = kLValueReference;
1661-
QT = cast<ReferenceType>(QT)->getPointeeType();
1664+
QT = cast<ReferenceType>(QT.getCanonicalType())->getPointeeType();
16621665
}
16631666
// Fall through for the array type to deal with reference/pointer ro array
16641667
// type.
@@ -1911,7 +1914,7 @@ namespace Cpp {
19111914
make_narg_ctor_with_return(FD, N, class_name, buf, indent_level);
19121915
return;
19131916
}
1914-
QualType QT = FD->getReturnType().getCanonicalType();
1917+
QualType QT = FD->getReturnType();
19151918
if (QT->isVoidType()) {
19161919
std::ostringstream typedefbuf;
19171920
std::ostringstream callbuf;

unittests/CppInterOp/FunctionReflectionTest.cpp

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

975975
FCI_Add.Invoke(&result, {args, /*args_size=*/2});
976976
EXPECT_EQ(result, a + b);
977+
978+
// typedef resolution testing
979+
Interp->process(R"(
980+
class TypedefToPrivateClass {
981+
private:
982+
class PC {
983+
public:
984+
int m_val = 4;
985+
};
986+
987+
public:
988+
typedef PC PP;
989+
static PP f() { return PC(); }
990+
};
991+
)");
992+
993+
Cpp::TCppScope_t TypedefToPrivateClass =
994+
Cpp::GetNamed("TypedefToPrivateClass");
995+
EXPECT_TRUE(TypedefToPrivateClass);
996+
997+
Cpp::TCppScope_t f = Cpp::GetNamed("f", TypedefToPrivateClass);
998+
EXPECT_TRUE(f);
999+
1000+
Cpp::JitCall FCI_f = Cpp::MakeFunctionCallable(f);
1001+
EXPECT_TRUE(FCI_f.getKind() == Cpp::JitCall::kGenericCall);
1002+
1003+
void* res = nullptr;
1004+
FCI_f.Invoke(&res, {nullptr, 0});
1005+
EXPECT_TRUE(res);
9771006
}
9781007

9791008
TEST(FunctionReflectionTest, IsConstMethod) {

0 commit comments

Comments
 (0)