r246778 - [libclang] Return deduced type for auto type, not the one written in the source.

Manuel Klimek via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 3 09:11:11 PDT 2015


Author: klimek
Date: Thu Sep  3 11:11:10 2015
New Revision: 246778

URL: http://llvm.org/viewvc/llvm-project?rev=246778&view=rev
Log:
[libclang] Return deduced type for auto type, not the one written in the source.

It used to work, but was accidentally broken by r179769.
The issue with decayed types was fixed by r190796.
So this patch partially reverts r179769, and adds more tests.

This also fixes PR 18669.

Patch by Sergey Kalinichev.

Modified:
    cfe/trunk/bindings/python/tests/cindex/test_type.py
    cfe/trunk/test/Index/print-type.cpp
    cfe/trunk/tools/libclang/CXType.cpp

Modified: cfe/trunk/bindings/python/tests/cindex/test_type.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_type.py?rev=246778&r1=246777&r2=246778&view=diff
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_type.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_type.py Thu Sep  3 11:11:10 2015
@@ -134,7 +134,7 @@ def test_equal():
 
 def test_type_spelling():
     """Ensure Type.spelling works."""
-    tu = get_tu('int c[5]; int i[]; int x; int v[x];')
+    tu = get_tu('int c[5]; void f(int i[]); int x; int v[x];')
     c = get_cursor(tu, 'c')
     i = get_cursor(tu, 'i')
     x = get_cursor(tu, 'x')
@@ -253,7 +253,7 @@ void bar(int a, int b);
 
 def test_element_type():
     """Ensure Type.element_type works."""
-    tu = get_tu('int c[5]; int i[]; int x; int v[x];')
+    tu = get_tu('int c[5]; void f(int i[]); int x; int v[x];')
     c = get_cursor(tu, 'c')
     i = get_cursor(tu, 'i')
     v = get_cursor(tu, 'v')

Modified: cfe/trunk/test/Index/print-type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-type.cpp?rev=246778&r1=246777&r2=246778&view=diff
==============================================================================
--- cfe/trunk/test/Index/print-type.cpp (original)
+++ cfe/trunk/test/Index/print-type.cpp Thu Sep  3 11:11:10 2015
@@ -48,7 +48,15 @@ struct Blob {
 };
 int Blob::*member_pointer;
 
-// RUN: c-index-test -test-print-type %s -std=c++11 | FileCheck %s
+
+
+auto autoI = 0;
+auto autoTbar = tbar<int>(0);
+auto autoBlob = new Blob();
+auto autoFunction(){return int();}
+decltype(auto) autoInt = 5;
+
+// RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: TemplateTypeParameter=T:3:19 (Definition) [type=T] [typekind=Unexposed] [canonicaltype=type-parameter-0-0] [canonicaltypekind=Unexposed] [isPOD=0]
@@ -119,3 +127,20 @@ int Blob::*member_pointer;
 // CHECK: StructDecl=Blob:45:8 (Definition) [type=Blob] [typekind=Record] [isPOD=1] [nbFields=2]
 // CHECK: FieldDecl=i:46:7 (Definition) [type=int] [typekind=Int] [isPOD=1]
 // CHECK: VarDecl=member_pointer:49:12 (Definition) [type=int Blob::*] [typekind=MemberPointer] [isPOD=1]
+// CHECK: VarDecl=autoI:53:6 (Definition) [type=int] [typekind=Unexposed] [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1]
+// CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
+// CHECK: VarDecl=autoTbar:54:6 (Definition) [type=int] [typekind=Unexposed] [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1]
+// CHECK: CallExpr=tbar:35:3 [type=int] [typekind=Unexposed] [canonicaltype=int] [canonicaltypekind=Int] [args= [int] [Int]] [isPOD=1]
+// CHECK: UnexposedExpr=tbar:35:3 [type=int (*)(int)] [typekind=Pointer] [canonicaltype=int (*)(int)] [canonicaltypekind=Pointer] [isPOD=1] [pointeetype=int (int)] [pointeekind=FunctionProto]
+// CHECK: DeclRefExpr=tbar:35:3 RefName=[54:17 - 54:21] RefName=[54:21 - 54:26] [type=int (int)] [typekind=FunctionProto] [canonicaltype=int (int)] [canonicaltypekind=FunctionProto] [isPOD=0]
+// CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
+// CHECK: VarDecl=autoBlob:55:6 (Definition) [type=Blob *] [typekind=Unexposed] [canonicaltype=Blob *] [canonicaltypekind=Pointer] [isPOD=1]
+// CHECK: CXXNewExpr= [type=Blob *] [typekind=Pointer] [isPOD=1] [pointeetype=Blob] [pointeekind=Record]
+// CHECK: TypeRef=struct Blob:45:8 [type=Blob] [typekind=Record] [isPOD=1] [nbFields=2]
+// CHECK: CallExpr=Blob:45:8 [type=Blob] [typekind=Record] [isPOD=1] [nbFields=2]
+// CHECK: FunctionDecl=autoFunction:56:6 (Definition) [type=int ()] [typekind=FunctionProto] [canonicaltype=int ()] [canonicaltypekind=FunctionProto] [resulttype=int] [resulttypekind=Unexposed] [isPOD=0]
+// CHECK: CompoundStmt= [type=] [typekind=Invalid] [isPOD=0]
+// CHECK: ReturnStmt= [type=] [typekind=Invalid] [isPOD=0]
+// CHECK: UnexposedExpr= [type=int] [typekind=Int] [isPOD=1]
+// CHECK: VarDecl=autoInt:57:16 (Definition) [type=int] [typekind=Unexposed] [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1]
+// CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]

Modified: cfe/trunk/tools/libclang/CXType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXType.cpp?rev=246778&r1=246777&r2=246778&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXType.cpp (original)
+++ cfe/trunk/tools/libclang/CXType.cpp Thu Sep  3 11:11:10 2015
@@ -164,20 +164,14 @@ CXType clang_getCursorType(CXCursor C) {
       return MakeCXType(Context.getTypeDeclType(TD), TU);
     if (const ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
       return MakeCXType(Context.getObjCInterfaceType(ID), TU);
-    if (const DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
-      if (TypeSourceInfo *TSInfo = DD->getTypeSourceInfo())
-        return MakeCXType(TSInfo->getType(), TU);
-      return MakeCXType(DD->getType(), TU);      
-    }
+    if (const DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D))
+      return MakeCXType(DD->getType(), TU);
     if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
       return MakeCXType(VD->getType(), TU);
     if (const ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(D))
       return MakeCXType(PD->getType(), TU);
-    if (const FunctionTemplateDecl *FTD = dyn_cast<FunctionTemplateDecl>(D)) {
-      if (TypeSourceInfo *TSInfo = FTD->getTemplatedDecl()->getTypeSourceInfo())
-        return MakeCXType(TSInfo->getType(), TU);
+    if (const FunctionTemplateDecl *FTD = dyn_cast<FunctionTemplateDecl>(D))
       return MakeCXType(FTD->getTemplatedDecl()->getType(), TU);
-    }
     return MakeCXType(QualType(), TU);
   }
   




More information about the cfe-commits mailing list