]> granicus.if.org Git - clang/commitdiff
[libclang] Don't report a DecayedType as "unexposed", report it as the original ...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 16 Sep 2013 17:26:23 +0000 (17:26 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 16 Sep 2013 17:26:23 +0000 (17:26 +0000)
Patch by Anders Waldenborg!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190796 91177308-0d34-0410-b5e6-96231b3b80d8

bindings/python/tests/cindex/test_type.py
test/Index/print-type.c
tools/libclang/CXType.cpp

index ed3d65c3789944e36208b38d0c6551ae07194ceb..62968d6285f98dabfd12841b4ce31ab8a49a58e1 100644 (file)
@@ -369,3 +369,13 @@ struct Test {
         assert teststruct.type.get_offset("bar") == bar
 
 
+def test_decay():
+    """Ensure decayed types are handled as the original type"""
+
+    tu = get_tu("void foo(int a[]);")
+    foo = get_cursor(tu, 'foo')
+    a = foo.type.argument_types()[0]
+
+    assert a.kind == TypeKind.INCOMPLETEARRAY
+    assert a.element_type.kind == TypeKind.INT
+    assert a.get_canonical().kind == TypeKind.INCOMPLETEARRAY
index 03f0b7c89ad69293d34e120e757ebbe1b77aae67..6c7095a4e5f5e0ce506e37282fb924920f3ad168 100644 (file)
@@ -10,6 +10,8 @@ typedef int ArrayType[5];
 int __attribute__((vector_size(16))) x;
 typedef int __attribute__((vector_size(16))) int4_t;
 
+int f2(int incompletearray[]);
+
 // RUN: c-index-test -test-print-type %s | FileCheck %s
 // CHECK: FunctionDecl=f:3:6 (Definition) [type=int *(int *, char *, FooType, int *, void (*)(int))] [typekind=FunctionProto] [canonicaltype=int *(int *, char *, int, int *, void (*)(int))] [canonicaltypekind=FunctionProto] [resulttype=int *] [resulttypekind=Pointer] [args= [int *] [Pointer] [char *] [Pointer] [FooType] [Typedef] [int [5]] [ConstantArray] [void (*)(int)] [Pointer]] [isPOD=0]
 // CHECK: ParmDecl=p:3:13 (Definition) [type=int *] [typekind=Pointer] [isPOD=1]
@@ -35,10 +37,11 @@ typedef int __attribute__((vector_size(16))) int4_t;
 // CHECK: DeclRefExpr=p:3:13 [type=int *] [typekind=Pointer] [isPOD=1]
 // CHECK: DeclRefExpr=z:3:33 [type=FooType] [typekind=Typedef] [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1]
 // CHECK: ArraySubscriptExpr= [type=int] [typekind=Int] [isPOD=1]
-// CHECK: UnexposedExpr=arr:3:40 [type=int *] [typekind=Unexposed] [canonicaltype=int *] [canonicaltypekind=Pointer] [isPOD=1]
+// CHECK: UnexposedExpr=arr:3:40 [type=int [5]] [typekind=ConstantArray] [isPOD=1]
 // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
 // CHECK: TypedefDecl=OtherType:8:16 (Definition) [type=OtherType] [typekind=Typedef] [canonicaltype=double] [canonicaltypekind=Double] [isPOD=1]
 // CHECK: TypedefDecl=ArrayType:9:13 (Definition) [type=ArrayType] [typekind=Typedef] [canonicaltype=int [5]] [canonicaltypekind=ConstantArray] [isPOD=1]
 // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
 // CHECK: VarDecl=x:10:38 [type=__attribute__((__vector_size__(4 * sizeof(int)))) int] [typekind=Vector] [isPOD=1]
 // CHECK: TypedefDecl=int4_t:11:46 (Definition) [type=int4_t] [typekind=Typedef] [canonicaltype=__attribute__((__vector_size__(4 * sizeof(int)))) int] [canonicaltypekind=Vector] [isPOD=1]
+// CHECK: ParmDecl=incompletearray:13:12 (Definition) [type=int []] [typekind=IncompleteArray] [isPOD=1]
index dcf69b5ba4b59a4fa06e79a706470ce6cccffb15..a7d6386b0270785308b04818a3d3548d5daec168 100644 (file)
@@ -110,6 +110,11 @@ CXType cxtype::MakeCXType(QualType T, CXTranslationUnit TU) {
       else if (Ctx.isObjCSelType(UnqualT))
         TK = CXType_ObjCSel;
     }
+
+    /* Handle decayed types as the original type */
+    if (const DecayedType *DT = T->getAs<DecayedType>()) {
+      return MakeCXType(DT->getOriginalType(), TU);
+    }
   }
   if (TK == CXType_Invalid)
     TK = GetTypeKind(T);