Author: smeenai Date: Tue May 1 13:45:25 2018 New Revision: 331306 URL: http://llvm.org/viewvc/llvm-project?rev=331306&view=rev Log: [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 Added: cfe/trunk/test/Index/paren-type.c Modified: cfe/trunk/test/Index/print-type.c cfe/trunk/tools/libclang/CXType.cpp Added: cfe/trunk/test/Index/paren-type.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/paren-type.c?rev=331306&view=auto ============================================================================== --- cfe/trunk/test/Index/paren-type.c (added) +++ cfe/trunk/test/Index/paren-type.c Tue May 1 13:45:25 2018 @@ -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); Modified: cfe/trunk/test/Index/print-type.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-type.c?rev=331306&r1=331305&r2=331306&view=diff ============================================================================== --- cfe/trunk/test/Index/print-type.c (original) +++ cfe/trunk/test/Index/print-type.c Tue May 1 13:45:25 2018 @@ -23,11 +23,11 @@ struct Struct{}; struct Struct elaborate // 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] Modified: cfe/trunk/tools/libclang/CXType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXType.cpp?rev=331306&r1=331305&r2=331306&view=diff ============================================================================== --- cfe/trunk/tools/libclang/CXType.cpp (original) +++ cfe/trunk/tools/libclang/CXType.cpp Tue May 1 13:45:25 2018 @@ -119,6 +119,10 @@ CXType cxtype::MakeCXType(QualType T, CX if (auto *ATT = T->getAs<AttributedType>()) { return MakeCXType(ATT->getModifiedType(), TU); } + // Handle paren types as the original type + if (auto *PTT = T->getAs<ParenType>()) { + return MakeCXType(PTT->getInnerType(), TU); + } ASTContext &Ctx = cxtu::getASTUnit(TU)->getASTContext(); if (Ctx.getLangOpts().ObjC1) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits