From aec83b75b754818ec4c59784b39f7fc60bc43d54 Mon Sep 17 00:00:00 2001 From: Shoaib Meenai Date: Tue, 1 May 2018 20:45:25 +0000 Subject: [PATCH] [libclang] Fix the type of 'int (Foo);' libclang exposes the type of 'int (Foo);' (a global variable of type int called Foo) as CXType_Unexposed. This is because Clang represents Foo's type as ParenType{BuiltinType{Int}}, and libclang does not handle ParenType. Make libclang return CXType_Int as the type of 'int (Foo);' by unwrapping ParenType transparently. Patch by Matt Glazar. Differential Revision: https://reviews.llvm.org/D45713 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@331306 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Index/paren-type.c | 16 ++++++++++++++++ test/Index/print-type.c | 4 ++-- tools/libclang/CXType.cpp | 4 ++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/Index/paren-type.c diff --git a/test/Index/paren-type.c b/test/Index/paren-type.c new file mode 100644 index 0000000000..14a7785e05 --- /dev/null +++ b/test/Index/paren-type.c @@ -0,0 +1,16 @@ +// RUN: c-index-test -test-print-type %s | FileCheck --check-prefix=CHECK-TYPE %s +// RUN: c-index-test -test-print-type-declaration %s | FileCheck --check-prefix=CHECK-TYPEDECL %s + +// CHECK-TYPE: VarDecl=VariableWithParentheses: +// CHECK-TYPE-SAME: [type=int] [typekind=Int] +// CHECK-TYPE-NOT: canonicaltype +// CHECK-TYPE-SAME: isPOD +extern int (VariableWithParentheses); + +typedef int MyTypedef; +// CHECK-TYPE: VarDecl=VariableWithParentheses2: +// CHECK-TYPE-SAME: [type=MyTypedef] [typekind=Typedef] +// CHECK-TYPE-SAME: [canonicaltype=int] [canonicaltypekind=Int] +// CHECK-TYPEDECL: VarDecl=VariableWithParentheses2 +// CHECK-TYPEDECL-SAME: [typedeclaration=MyTypedef] [typekind=Typedef] +extern MyTypedef (VariableWithParentheses2); diff --git a/test/Index/print-type.c b/test/Index/print-type.c index ebe42970ee..13c7655437 100644 --- a/test/Index/print-type.c +++ b/test/Index/print-type.c @@ -23,11 +23,11 @@ struct Struct{}; struct Struct elaboratedStructType(); // CHECK: TypeRef=FooType:1:13 [type=FooType] [typekind=Typedef] [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1] // CHECK: ParmDecl=arr:3:40 (Definition) [type=int [5]] [typekind=ConstantArray] [isPOD=1] // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1] -// CHECK: ParmDecl=fn:3:55 (Definition) [type=void (*)(int)] [typekind=Pointer] [canonicaltype=void (*)(int)] [canonicaltypekind=Pointer] [isPOD=1] [pointeetype=void (int)] [pointeekind=Unexposed] +// CHECK: ParmDecl=fn:3:55 (Definition) [type=void (*)(int)] [typekind=Pointer] [canonicaltype=void (*)(int)] [canonicaltypekind=Pointer] [isPOD=1] [pointeetype=void (int)] [pointeekind=FunctionProto] // CHECK: ParmDecl=:3:62 (Definition) [type=int] [typekind=Int] [isPOD=1] // CHECK: CompoundStmt= [type=] [typekind=Invalid] [isPOD=0] // CHECK: CallExpr=fn:3:55 [type=void] [typekind=Void] [args= [int] [Int]] [isPOD=0] -// CHECK: DeclRefExpr=fn:3:55 [type=void (*)(int)] [typekind=Pointer] [canonicaltype=void (*)(int)] [canonicaltypekind=Pointer] [isPOD=1] [pointeetype=void (int)] [pointeekind=Unexposed] +// CHECK: DeclRefExpr=fn:3:55 [type=void (*)(int)] [typekind=Pointer] [canonicaltype=void (*)(int)] [canonicaltypekind=Pointer] [isPOD=1] [pointeetype=void (int)] [pointeekind=FunctionProto] // CHECK: UnaryOperator= [type=int] [typekind=Int] [isPOD=1] // CHECK: DeclRefExpr=p:3:13 [type=int *] [typekind=Pointer] [isPOD=1] [pointeetype=int] [pointeekind=Int] // CHECK: DeclStmt= [type=] [typekind=Invalid] [isPOD=0] diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp index dfc0152477..e01b36f367 100644 --- a/tools/libclang/CXType.cpp +++ b/tools/libclang/CXType.cpp @@ -119,6 +119,10 @@ CXType cxtype::MakeCXType(QualType T, CXTranslationUnit TU) { if (auto *ATT = T->getAs()) { return MakeCXType(ATT->getModifiedType(), TU); } + // Handle paren types as the original type + if (auto *PTT = T->getAs()) { + return MakeCXType(PTT->getInnerType(), TU); + } ASTContext &Ctx = cxtu::getASTUnit(TU)->getASTContext(); if (Ctx.getLangOpts().ObjC1) { -- 2.40.0