[PATCH] D58571: [libclang] Fix a trivial error introduced in D57946.

2019-02-25 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL354823: [libclang] Fix a trivial error introduced in D57946. 
(authored by emilio, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D58571?vs=188027&id=188249#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58571/new/

https://reviews.llvm.org/D58571

Files:
  cfe/trunk/bindings/python/clang/cindex.py


Index: cfe/trunk/bindings/python/clang/cindex.py
===
--- cfe/trunk/bindings/python/clang/cindex.py
+++ cfe/trunk/bindings/python/clang/cindex.py
@@ -1342,7 +1342,7 @@
 
 CursorKind.DLLEXPORT_ATTR = CursorKind(418)
 CursorKind.DLLIMPORT_ATTR = CursorKind(419)
-CursorKind.CONVERGENT_ATTR = CursorKind(420)
+CursorKind.CONVERGENT_ATTR = CursorKind(438)
 
 ###
 # Preprocessing


Index: cfe/trunk/bindings/python/clang/cindex.py
===
--- cfe/trunk/bindings/python/clang/cindex.py
+++ cfe/trunk/bindings/python/clang/cindex.py
@@ -1342,7 +1342,7 @@
 
 CursorKind.DLLEXPORT_ATTR = CursorKind(418)
 CursorKind.DLLIMPORT_ATTR = CursorKind(419)
-CursorKind.CONVERGENT_ATTR = CursorKind(420)
+CursorKind.CONVERGENT_ATTR = CursorKind(438)
 
 ###
 # Preprocessing
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58570: [libclang] Expose warn_unused and warn_unused_result attributes.

2019-02-25 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC354824: [libclang] Expose warn_unused and warn_unused_result 
attributes. (authored by emilio, committed by ).
Herald added a reviewer: serge-sans-paille.

Changed prior to commit:
  https://reviews.llvm.org/D58570?vs=188026&id=188251#toc

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58570/new/

https://reviews.llvm.org/D58570

Files:
  bindings/python/clang/cindex.py
  include/clang-c/Index.h
  test/Index/attributes.c
  tools/libclang/CIndex.cpp
  tools/libclang/CXCursor.cpp


Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -5477,6 +5477,10 @@
   return cxstring::createRef("FriendDecl");
   case CXCursor_ConvergentAttr:
   return cxstring::createRef("attribute(convergent)");
+  case CXCursor_WarnUnusedAttr:
+  return cxstring::createRef("attribute(warn_unused)");
+  case CXCursor_WarnUnusedResultAttr:
+  return cxstring::createRef("attribute(warn_unused_result)");
   }
 
   llvm_unreachable("Unhandled CXCursorKind");
Index: tools/libclang/CXCursor.cpp
===
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -79,6 +79,8 @@
 case attr::ObjCBoxable: return CXCursor_ObjCBoxable;
 case attr::FlagEnum: return CXCursor_FlagEnum;
 case attr::Convergent: return CXCursor_ConvergentAttr;
+case attr::WarnUnused: return CXCursor_WarnUnusedAttr;
+case attr::WarnUnusedResult: return CXCursor_WarnUnusedResultAttr;
   }
 
   return CXCursor_UnexposedAttr;
Index: bindings/python/clang/cindex.py
===
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -1343,6 +1343,8 @@
 CursorKind.DLLEXPORT_ATTR = CursorKind(418)
 CursorKind.DLLIMPORT_ATTR = CursorKind(419)
 CursorKind.CONVERGENT_ATTR = CursorKind(438)
+CursorKind.WARN_UNUSED_ATTR = CursorKind(439)
+CursorKind.WARN_UNUSED_RESULT_ATTR = CursorKind(440)
 
 ###
 # Preprocessing
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 51
+#define CINDEX_VERSION_MINOR 52
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -2587,7 +2587,9 @@
   CXCursor_ObjCBoxable   = 436,
   CXCursor_FlagEnum  = 437,
   CXCursor_ConvergentAttr= 438,
-  CXCursor_LastAttr  = CXCursor_ConvergentAttr,
+  CXCursor_WarnUnusedAttr= 439,
+  CXCursor_WarnUnusedResultAttr  = 440,
+  CXCursor_LastAttr  = CXCursor_WarnUnusedResultAttr,
 
   /* Preprocessing */
   CXCursor_PreprocessingDirective= 500,
Index: test/Index/attributes.c
===
--- test/Index/attributes.c
+++ test/Index/attributes.c
@@ -14,6 +14,12 @@
 
 void convergent_fn() __attribute__((convergent));
 
+int warn_unused_result_fn() __attribute__((warn_unused_result));
+
+struct __attribute__((warn_unused)) WarnUnused {
+  int b;
+};
+
 // CHECK: attributes.c:3:32: StructDecl=Test2:3:32 (Definition) Extent=[3:1 - 
5:2]
 // CHECK: attributes.c:3:23: attribute(packed)=packed Extent=[3:23 - 3:29]
 // CHECK: attributes.c:4:8: FieldDecl=a:4:8 (Definition) Extent=[4:3 - 4:9] 
[access=public]
@@ -29,3 +35,7 @@
 // CHECK: attributes.c:12:3: EnumConstantDecl=Foo:12:3 (Definition) 
Extent=[12:3 - 12:6]
 // CHECK: attributes.c:15:6: FunctionDecl=convergent_fn:15:6 Extent=[15:1 - 
15:49]
 // CHECK: attributes.c:15:37: attribute(convergent)= Extent=[15:37 - 15:47]
+// CHECK: attributes.c:17:5: FunctionDecl=warn_unused_result_fn:17:5 
Extent=[17:1 - 17:64]
+// CHECK: attributes.c:17:44: attribute(warn_unused_result)= Extent=[17:44 - 
17:62]
+// CHECK: attributes.c:19:37: StructDecl=WarnUnused:19:37 (Definition) 
Extent=[19:1 - 21:2]
+// CHECK: attributes.c:19:23: attribute(warn_unused)= Extent=[19:23 - 19:34]


Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -5477,6 +5477,10 @@
   return cxstring::createRef("FriendDecl");
   case CXCursor_ConvergentAttr:
   return cxstring::createRef("attribute(convergent)");
+  case CXCursor_WarnUnusedAttr:
+  return cxstring::createRef("attribute(warn_unused)");
+  case CXCursor_WarnUnusedResultAttr:
+  return cxstring::createRef("attribute(warn_unused_result)");
   }
 
   llvm_unreachable("Unhandled CXCursorKind");
Index: tools/libclang/CXCursor.cpp

[PATCH] D58570: [libclang] Expose warn_unused and warn_unused_result attributes.

2019-02-25 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a comment.

Landed with that change, thanks for the review @anastasia!


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58570/new/

https://reviews.llvm.org/D58570



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58569: [libclang] Avoid crashing when getting layout info of an undeduced type.

2019-02-25 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio updated this revision to Diff 188254.
emilio marked an inline comment as done.
emilio added a comment.

Add CHECK tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58569/new/

https://reviews.llvm.org/D58569

Files:
  clang/include/clang-c/Index.h
  clang/test/Index/print-type-size.cpp
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -891,6 +891,9 @@
 return CXTypeLayoutError_Incomplete;
   if (QT->isDependentType())
 return CXTypeLayoutError_Dependent;
+  if (const auto *Deduced = dyn_cast(QT))
+if (Deduced->getDeducedType().isNull())
+  return CXTypeLayoutError_Undeduced;
   // Exceptions by GCC extension - see ASTContext.cpp:1313 getTypeInfoImpl
   // if (QT->isFunctionType()) return 4; // Bug #15511 - should be 1
   // if (QT->isVoidType()) return 1;
@@ -928,6 +931,9 @@
 return CXTypeLayoutError_Dependent;
   if (!QT->isConstantSizeType())
 return CXTypeLayoutError_NotConstantSize;
+  if (const auto *Deduced = dyn_cast(QT))
+if (Deduced->getDeducedType().isNull())
+  return CXTypeLayoutError_Undeduced;
   // [gcc extension] lib/AST/ExprConstant.cpp:1372
   // HandleSizeof : {voidtype,functype} == 1
   // not handled by ASTContext.cpp:1313 getTypeInfoImpl
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -1670,29 +1670,44 @@
   return CXChildVisit_Recurse;
 }
 
-static enum CXChildVisitResult PrintTypeSize(CXCursor cursor, CXCursor p,
- CXClientData d) {
-  CXType T;
-  enum CXCursorKind K = clang_getCursorKind(cursor);
-  if (clang_isInvalid(K))
-return CXChildVisit_Recurse;
-  T = clang_getCursorType(cursor);
-  PrintCursor(cursor, NULL);
-  PrintTypeAndTypeKind(T, " [type=%s] [typekind=%s]");
+static void PrintSingleTypeSize(CXType T, const char *TypeKindFormat,
+const char *SizeFormat,
+const char *AlignFormat) {
+  PrintTypeAndTypeKind(T, TypeKindFormat);
   /* Print the type sizeof if applicable. */
   {
 long long Size = clang_Type_getSizeOf(T);
 if (Size >= 0 || Size < -1 ) {
-  printf(" [sizeof=%lld]", Size);
+  printf(SizeFormat, Size);
 }
   }
   /* Print the type alignof if applicable. */
   {
 long long Align = clang_Type_getAlignOf(T);
 if (Align >= 0 || Align < -1) {
-  printf(" [alignof=%lld]", Align);
+  printf(AlignFormat, Align);
 }
   }
+
+  /* Print the return type if it exists. */
+  {
+CXType RT = clang_getResultType(T);
+if (RT.kind != CXType_Invalid)
+  PrintSingleTypeSize(RT, " [resulttype=%s] [resulttypekind=%s]",
+  " [resultsizeof=%lld]", " [resultalignof=%lld]");
+  }
+}
+
+static enum CXChildVisitResult PrintTypeSize(CXCursor cursor, CXCursor p,
+ CXClientData d) {
+  CXType T;
+  enum CXCursorKind K = clang_getCursorKind(cursor);
+  if (clang_isInvalid(K))
+return CXChildVisit_Recurse;
+  T = clang_getCursorType(cursor);
+  PrintCursor(cursor, NULL);
+  PrintSingleTypeSize(T, " [type=%s] [typekind=%s]", " [sizeof=%lld]",
+  " [alignof=%lld]");
   /* Print the record field offset if applicable. */
   {
 CXString FieldSpelling = clang_getCursorSpelling(cursor);
@@ -1730,7 +1745,9 @@
 if (IsBitfield)
   printf(" [BitFieldSize=%d]", clang_getFieldDeclBitWidth(cursor));
   }
+
   printf("\n");
+
   return CXChildVisit_Recurse;
 }
 
Index: clang/test/Index/print-type-size.cpp
===
--- clang/test/Index/print-type-size.cpp
+++ clang/test/Index/print-type-size.cpp
@@ -400,4 +400,10 @@
 struct lastValid {
 };
 
+// CHECK64: CXXMethod=Tie:[[@LINE+3]]:8 (const) [type=auto (void *) const] [typekind=FunctionProto] [sizeof=1] [alignof=4] [resulttype=auto] [resulttypekind=Auto] [resultsizeof=-6] [resultalignof=-6]
+// CHECK32: CXXMethod=Tie:[[@LINE+2]]:8 (const) [type=auto (void *) const] [typekind=FunctionProto] [sizeof=1] [alignof=4] [resulttype=auto] [resulttypekind=Auto] [resultsizeof=-6] [resultalignof=-6]
+class BrowsingContext {
+  auto Tie(void*) const;
+};
+
 }
Index: clang/include/clang-c/Index.h
===
--- clang/include/clang-c/Index.h
+++ clang/include/clang-c/Index.h
@@ -3841,7 +3841,11 @@
   /**
* The Field name is not valid for this record.
*/
-  CXTypeLayoutError_InvalidFieldName = -5
+  CXTypeLayoutError_InvalidFieldName = -5,
+  /**
+   * The type is undeduced.
+   */
+  CXTypeLayoutError_Undeduced = -6
 };
 

[PATCH] D58569: [libclang] Avoid crashing when getting layout info of an undeduced type.

2019-02-25 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio marked 2 inline comments as done.
emilio added a comment.

Huh, somehow forgot to press "Submit" this morning :)




Comment at: clang/tools/c-index-test/c-index-test.c:1695
+CXType RT = clang_getResultType(T);
+if (RT.kind != CXType_Invalid)
+  PrintSingleTypeSize(RT, " [resulttype=%s] [resulttypekind=%s]",

Anastasia wrote:
> emilio wrote:
> > Anastasia wrote:
> > > Should it not return undeduced error in the other case?
> > I'm not sure what you mean, can you clarify?
> > 
> > The undeduced error is only returned when you try to access the `Auto` type 
> > which is the return value, not the function type, which has a known layout.
> > 
> > So in the error case, `T` here is the `auto Tie(void*) const;` type, and 
> > `RT` is the undeduced `auto` type, which is what crashed.
> > 
> > We had no way to exercise this in `c-index-test`, so I changed it to 
> > exercise this codepath too. I can add a `CHECK` for the error code if you 
> > want.
> Yep, error check would be good since it's covers better changes in your patch.
Alrighty, done!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58569/new/

https://reviews.llvm.org/D58569



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58569: [libclang] Avoid crashing when getting layout info of an undeduced type.

2019-02-26 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
emilio marked an inline comment as done.
Closed by commit rC354885: [libclang] Avoid crashing when getting layout info 
of an undeduced type. (authored by emilio, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D58569?vs=188254&id=188371#toc

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58569/new/

https://reviews.llvm.org/D58569

Files:
  include/clang-c/Index.h
  test/Index/print-type-size.cpp
  tools/c-index-test/c-index-test.c
  tools/libclang/CXType.cpp

Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 52
+#define CINDEX_VERSION_MINOR 53
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -3841,7 +3841,11 @@
   /**
* The Field name is not valid for this record.
*/
-  CXTypeLayoutError_InvalidFieldName = -5
+  CXTypeLayoutError_InvalidFieldName = -5,
+  /**
+   * The type is undeduced.
+   */
+  CXTypeLayoutError_Undeduced = -6
 };
 
 /**
Index: test/Index/print-type-size.cpp
===
--- test/Index/print-type-size.cpp
+++ test/Index/print-type-size.cpp
@@ -400,4 +400,10 @@
 struct lastValid {
 };
 
+// CHECK64: CXXMethod=Tie:[[@LINE+3]]:8 (const) [type=auto (void *) const] [typekind=FunctionProto] [sizeof=1] [alignof=4] [resulttype=auto] [resulttypekind=Auto] [resultsizeof=-6] [resultalignof=-6]
+// CHECK32: CXXMethod=Tie:[[@LINE+2]]:8 (const) [type=auto (void *) const] [typekind=FunctionProto] [sizeof=1] [alignof=4] [resulttype=auto] [resulttypekind=Auto] [resultsizeof=-6] [resultalignof=-6]
+class BrowsingContext {
+  auto Tie(void*) const;
+};
+
 }
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1670,29 +1670,44 @@
   return CXChildVisit_Recurse;
 }
 
-static enum CXChildVisitResult PrintTypeSize(CXCursor cursor, CXCursor p,
- CXClientData d) {
-  CXType T;
-  enum CXCursorKind K = clang_getCursorKind(cursor);
-  if (clang_isInvalid(K))
-return CXChildVisit_Recurse;
-  T = clang_getCursorType(cursor);
-  PrintCursor(cursor, NULL);
-  PrintTypeAndTypeKind(T, " [type=%s] [typekind=%s]");
+static void PrintSingleTypeSize(CXType T, const char *TypeKindFormat,
+const char *SizeFormat,
+const char *AlignFormat) {
+  PrintTypeAndTypeKind(T, TypeKindFormat);
   /* Print the type sizeof if applicable. */
   {
 long long Size = clang_Type_getSizeOf(T);
 if (Size >= 0 || Size < -1 ) {
-  printf(" [sizeof=%lld]", Size);
+  printf(SizeFormat, Size);
 }
   }
   /* Print the type alignof if applicable. */
   {
 long long Align = clang_Type_getAlignOf(T);
 if (Align >= 0 || Align < -1) {
-  printf(" [alignof=%lld]", Align);
+  printf(AlignFormat, Align);
 }
   }
+
+  /* Print the return type if it exists. */
+  {
+CXType RT = clang_getResultType(T);
+if (RT.kind != CXType_Invalid)
+  PrintSingleTypeSize(RT, " [resulttype=%s] [resulttypekind=%s]",
+  " [resultsizeof=%lld]", " [resultalignof=%lld]");
+  }
+}
+
+static enum CXChildVisitResult PrintTypeSize(CXCursor cursor, CXCursor p,
+ CXClientData d) {
+  CXType T;
+  enum CXCursorKind K = clang_getCursorKind(cursor);
+  if (clang_isInvalid(K))
+return CXChildVisit_Recurse;
+  T = clang_getCursorType(cursor);
+  PrintCursor(cursor, NULL);
+  PrintSingleTypeSize(T, " [type=%s] [typekind=%s]", " [sizeof=%lld]",
+  " [alignof=%lld]");
   /* Print the record field offset if applicable. */
   {
 CXString FieldSpelling = clang_getCursorSpelling(cursor);
@@ -1730,7 +1745,9 @@
 if (IsBitfield)
   printf(" [BitFieldSize=%d]", clang_getFieldDeclBitWidth(cursor));
   }
+
   printf("\n");
+
   return CXChildVisit_Recurse;
 }
 
Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -891,6 +891,9 @@
 return CXTypeLayoutError_Incomplete;
   if (QT->isDependentType())
 return CXTypeLayoutError_Dependent;
+  if (const auto *Deduced = dyn_cast(QT))
+if (Deduced->getDeducedType().isNull())
+  return CXTypeLayoutError_Undeduced;
   // Exceptions by GCC extension - see ASTContext.cpp:1313 getTypeInfoImpl
   // if (QT->isFunctionType()) return 4; // Bug #15511 - should be 1
   // if (QT->isVoidType()) return 1;
@@ -928,6 +931,9 @@
 return CXTypeLayoutError

[PATCH] D58569: [libclang] Avoid crashing when getting layout info of an undeduced type.

2019-02-26 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a comment.

Thank you for all the reviews! :)


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58569/new/

https://reviews.llvm.org/D58569



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59299: [libclang] Expose aligned() attribute.

2019-03-13 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio created this revision.
emilio added reviewers: Anastasia, arphaman.
Herald added a reviewer: serge-sans-paille.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is useful because otherwise there's no easy way to distinguish #pragma
packed(N) from attribute(packed, aligned(N)) that isn't looking at field
offsets (since pragma packed() also creates a packed attribute).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D59299

Files:
  clang/bindings/python/clang/cindex.py
  clang/include/clang-c/Index.h
  clang/test/Index/attributes.c
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp


Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -81,6 +81,7 @@
 case attr::Convergent: return CXCursor_ConvergentAttr;
 case attr::WarnUnused: return CXCursor_WarnUnusedAttr;
 case attr::WarnUnusedResult: return CXCursor_WarnUnusedResultAttr;
+case attr::Aligned: return CXCursor_AlignedAttr;
   }
 
   return CXCursor_UnexposedAttr;
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -5484,6 +5484,8 @@
   return cxstring::createRef("attribute(warn_unused)");
   case CXCursor_WarnUnusedResultAttr:
   return cxstring::createRef("attribute(warn_unused_result)");
+  case CXCursor_AlignedAttr:
+  return cxstring::createRef("attribute(aligned)");
   }
 
   llvm_unreachable("Unhandled CXCursorKind");
Index: clang/test/Index/attributes.c
===
--- clang/test/Index/attributes.c
+++ clang/test/Index/attributes.c
@@ -20,6 +20,14 @@
   int b;
 };
 
+struct __attribute__((aligned(64))) Aligned1 {
+  int c;
+};
+
+struct Aligned2 {
+  int c;
+} __attribute__((aligned(64)));
+
 // CHECK: attributes.c:3:32: StructDecl=Test2:3:32 (Definition) Extent=[3:1 - 
5:2]
 // CHECK: attributes.c:3:23: attribute(packed)=packed Extent=[3:23 - 3:29]
 // CHECK: attributes.c:4:8: FieldDecl=a:4:8 (Definition) Extent=[4:3 - 4:9] 
[access=public]
@@ -39,3 +47,7 @@
 // CHECK: attributes.c:17:44: attribute(warn_unused_result)= Extent=[17:44 - 
17:62]
 // CHECK: attributes.c:19:37: StructDecl=WarnUnused:19:37 (Definition) 
Extent=[19:1 - 21:2]
 // CHECK: attributes.c:19:23: attribute(warn_unused)= Extent=[19:23 - 19:34]
+// CHECK: attributes.c:23:37: StructDecl=Aligned1:23:37 (Definition) 
Extent=[23:1 - 25:2]
+// CHECK: attributes.c:23:23: attribute(aligned)= Extent=[23:23 - 23:34]
+// CHECK: attributes.c:27:8: StructDecl=Aligned2:27:8 (Definition) 
Extent=[27:1 - 29:2]
+// CHECK: attributes.c:29:18: attribute(aligned)= Extent=[29:18 - 29:29]
Index: clang/include/clang-c/Index.h
===
--- clang/include/clang-c/Index.h
+++ clang/include/clang-c/Index.h
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 53
+#define CINDEX_VERSION_MINOR 54
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -2589,7 +2589,8 @@
   CXCursor_ConvergentAttr= 438,
   CXCursor_WarnUnusedAttr= 439,
   CXCursor_WarnUnusedResultAttr  = 440,
-  CXCursor_LastAttr  = CXCursor_WarnUnusedResultAttr,
+  CXCursor_AlignedAttr   = 441,
+  CXCursor_LastAttr  = CXCursor_AlignedAttr,
 
   /* Preprocessing */
   CXCursor_PreprocessingDirective= 500,
Index: clang/bindings/python/clang/cindex.py
===
--- clang/bindings/python/clang/cindex.py
+++ clang/bindings/python/clang/cindex.py
@@ -1345,6 +1345,7 @@
 CursorKind.CONVERGENT_ATTR = CursorKind(438)
 CursorKind.WARN_UNUSED_ATTR = CursorKind(439)
 CursorKind.WARN_UNUSED_RESULT_ATTR = CursorKind(440)
+CursorKind.ALIGNED_ATTR = CursorKind(441)
 
 ###
 # Preprocessing


Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -81,6 +81,7 @@
 case attr::Convergent: return CXCursor_ConvergentAttr;
 case attr::WarnUnused: return CXCursor_WarnUnusedAttr;
 case attr::WarnUnusedResult: return CXCursor_WarnUnusedResultAttr;
+case attr::Aligned: return CXCursor_AlignedAttr;
   }
 
   return CXCursor_UnexposedAttr;
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -5484,6 +5484,8 @@
   return cxstring::createRef("attribute(warn_unused)");
   case CXCursor_WarnUnusedResultAttr:
   return c

[PATCH] D59299: [libclang] Expose aligned() attribute.

2019-03-13 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL356062: [libclang] Expose aligned() attribute. (authored by 
emilio, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D59299?vs=190414&id=190430#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59299/new/

https://reviews.llvm.org/D59299

Files:
  cfe/trunk/bindings/python/clang/cindex.py
  cfe/trunk/include/clang-c/Index.h
  cfe/trunk/test/Index/attributes.c
  cfe/trunk/tools/libclang/CIndex.cpp
  cfe/trunk/tools/libclang/CXCursor.cpp


Index: cfe/trunk/tools/libclang/CIndex.cpp
===
--- cfe/trunk/tools/libclang/CIndex.cpp
+++ cfe/trunk/tools/libclang/CIndex.cpp
@@ -5484,6 +5484,8 @@
   return cxstring::createRef("attribute(warn_unused)");
   case CXCursor_WarnUnusedResultAttr:
   return cxstring::createRef("attribute(warn_unused_result)");
+  case CXCursor_AlignedAttr:
+  return cxstring::createRef("attribute(aligned)");
   }
 
   llvm_unreachable("Unhandled CXCursorKind");
Index: cfe/trunk/tools/libclang/CXCursor.cpp
===
--- cfe/trunk/tools/libclang/CXCursor.cpp
+++ cfe/trunk/tools/libclang/CXCursor.cpp
@@ -81,6 +81,7 @@
 case attr::Convergent: return CXCursor_ConvergentAttr;
 case attr::WarnUnused: return CXCursor_WarnUnusedAttr;
 case attr::WarnUnusedResult: return CXCursor_WarnUnusedResultAttr;
+case attr::Aligned: return CXCursor_AlignedAttr;
   }
 
   return CXCursor_UnexposedAttr;
Index: cfe/trunk/bindings/python/clang/cindex.py
===
--- cfe/trunk/bindings/python/clang/cindex.py
+++ cfe/trunk/bindings/python/clang/cindex.py
@@ -1345,6 +1345,7 @@
 CursorKind.CONVERGENT_ATTR = CursorKind(438)
 CursorKind.WARN_UNUSED_ATTR = CursorKind(439)
 CursorKind.WARN_UNUSED_RESULT_ATTR = CursorKind(440)
+CursorKind.ALIGNED_ATTR = CursorKind(441)
 
 ###
 # Preprocessing
Index: cfe/trunk/include/clang-c/Index.h
===
--- cfe/trunk/include/clang-c/Index.h
+++ cfe/trunk/include/clang-c/Index.h
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 53
+#define CINDEX_VERSION_MINOR 54
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -2589,7 +2589,8 @@
   CXCursor_ConvergentAttr= 438,
   CXCursor_WarnUnusedAttr= 439,
   CXCursor_WarnUnusedResultAttr  = 440,
-  CXCursor_LastAttr  = CXCursor_WarnUnusedResultAttr,
+  CXCursor_AlignedAttr   = 441,
+  CXCursor_LastAttr  = CXCursor_AlignedAttr,
 
   /* Preprocessing */
   CXCursor_PreprocessingDirective= 500,
Index: cfe/trunk/test/Index/attributes.c
===
--- cfe/trunk/test/Index/attributes.c
+++ cfe/trunk/test/Index/attributes.c
@@ -20,6 +20,14 @@
   int b;
 };
 
+struct __attribute__((aligned(64))) Aligned1 {
+  int c;
+};
+
+struct Aligned2 {
+  int c;
+} __attribute__((aligned(64)));
+
 // CHECK: attributes.c:3:32: StructDecl=Test2:3:32 (Definition) Extent=[3:1 - 
5:2]
 // CHECK: attributes.c:3:23: attribute(packed)=packed Extent=[3:23 - 3:29]
 // CHECK: attributes.c:4:8: FieldDecl=a:4:8 (Definition) Extent=[4:3 - 4:9] 
[access=public]
@@ -39,3 +47,7 @@
 // CHECK: attributes.c:17:44: attribute(warn_unused_result)= Extent=[17:44 - 
17:62]
 // CHECK: attributes.c:19:37: StructDecl=WarnUnused:19:37 (Definition) 
Extent=[19:1 - 21:2]
 // CHECK: attributes.c:19:23: attribute(warn_unused)= Extent=[19:23 - 19:34]
+// CHECK: attributes.c:23:37: StructDecl=Aligned1:23:37 (Definition) 
Extent=[23:1 - 25:2]
+// CHECK: attributes.c:23:23: attribute(aligned)= Extent=[23:23 - 23:34]
+// CHECK: attributes.c:27:8: StructDecl=Aligned2:27:8 (Definition) 
Extent=[27:1 - 29:2]
+// CHECK: attributes.c:29:18: attribute(aligned)= Extent=[29:18 - 29:29]


Index: cfe/trunk/tools/libclang/CIndex.cpp
===
--- cfe/trunk/tools/libclang/CIndex.cpp
+++ cfe/trunk/tools/libclang/CIndex.cpp
@@ -5484,6 +5484,8 @@
   return cxstring::createRef("attribute(warn_unused)");
   case CXCursor_WarnUnusedResultAttr:
   return cxstring::createRef("attribute(warn_unused_result)");
+  case CXCursor_AlignedAttr:
+  return cxstring::createRef("attribute(aligned)");
   }
 
   llvm_unreachable("Unhandled CXCursorKind");
Index: cfe/trunk/tools/libclang/CXCursor.cpp
===
--- cfe/trunk/tools/libclang/CXCursor.cpp
+++ cfe/trunk/tools/libclang/CXCursor.cpp
@@ -81,6 +81,7 @@
 case at

[PATCH] D59299: [libclang] Expose aligned() attribute.

2019-03-13 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a comment.

Thank you for the review! :)


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59299/new/

https://reviews.llvm.org/D59299



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58569: [libclang] Avoid crashing when getting layout info of an undeduced type.

2019-02-22 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio created this revision.
Herald added subscribers: cfe-commits, arphaman.
Herald added a project: clang.

When the type is not deducible, return an error instead of crashing.

This fixes https://bugs.llvm.org/show_bug.cgi?id=40813.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D58569

Files:
  clang/include/clang-c/Index.h
  clang/test/Index/print-type-size.cpp
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -891,6 +891,9 @@
 return CXTypeLayoutError_Incomplete;
   if (QT->isDependentType())
 return CXTypeLayoutError_Dependent;
+  if (const auto *Deduced = dyn_cast(QT))
+if (Deduced->getDeducedType().isNull())
+  return CXTypeLayoutError_Undeduced;
   // Exceptions by GCC extension - see ASTContext.cpp:1313 getTypeInfoImpl
   // if (QT->isFunctionType()) return 4; // Bug #15511 - should be 1
   // if (QT->isVoidType()) return 1;
@@ -928,6 +931,9 @@
 return CXTypeLayoutError_Dependent;
   if (!QT->isConstantSizeType())
 return CXTypeLayoutError_NotConstantSize;
+  if (const auto *Deduced = dyn_cast(QT))
+if (Deduced->getDeducedType().isNull())
+  return CXTypeLayoutError_Undeduced;
   // [gcc extension] lib/AST/ExprConstant.cpp:1372
   // HandleSizeof : {voidtype,functype} == 1
   // not handled by ASTContext.cpp:1313 getTypeInfoImpl
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -1670,29 +1670,44 @@
   return CXChildVisit_Recurse;
 }
 
-static enum CXChildVisitResult PrintTypeSize(CXCursor cursor, CXCursor p,
- CXClientData d) {
-  CXType T;
-  enum CXCursorKind K = clang_getCursorKind(cursor);
-  if (clang_isInvalid(K))
-return CXChildVisit_Recurse;
-  T = clang_getCursorType(cursor);
-  PrintCursor(cursor, NULL);
-  PrintTypeAndTypeKind(T, " [type=%s] [typekind=%s]");
+static void PrintSingleTypeSize(CXType T, const char *TypeKindFormat,
+const char *SizeFormat,
+const char *AlignFormat) {
+  PrintTypeAndTypeKind(T, TypeKindFormat);
   /* Print the type sizeof if applicable. */
   {
 long long Size = clang_Type_getSizeOf(T);
 if (Size >= 0 || Size < -1 ) {
-  printf(" [sizeof=%lld]", Size);
+  printf(SizeFormat, Size);
 }
   }
   /* Print the type alignof if applicable. */
   {
 long long Align = clang_Type_getAlignOf(T);
 if (Align >= 0 || Align < -1) {
-  printf(" [alignof=%lld]", Align);
+  printf(AlignFormat, Align);
 }
   }
+
+  /* Print the return type if it exists. */
+  {
+CXType RT = clang_getResultType(T);
+if (RT.kind != CXType_Invalid)
+  PrintSingleTypeSize(RT, " [resulttype=%s] [resulttypekind=%s]",
+  " [resultsizeof=%lld]", " [resultalignof=%lld]");
+  }
+}
+
+static enum CXChildVisitResult PrintTypeSize(CXCursor cursor, CXCursor p,
+ CXClientData d) {
+  CXType T;
+  enum CXCursorKind K = clang_getCursorKind(cursor);
+  if (clang_isInvalid(K))
+return CXChildVisit_Recurse;
+  T = clang_getCursorType(cursor);
+  PrintCursor(cursor, NULL);
+  PrintSingleTypeSize(T, " [type=%s] [typekind=%s]", " [sizeof=%lld]",
+  " [alignof=%lld]");
   /* Print the record field offset if applicable. */
   {
 CXString FieldSpelling = clang_getCursorSpelling(cursor);
@@ -1730,7 +1745,9 @@
 if (IsBitfield)
   printf(" [BitFieldSize=%d]", clang_getFieldDeclBitWidth(cursor));
   }
+
   printf("\n");
+
   return CXChildVisit_Recurse;
 }
 
Index: clang/test/Index/print-type-size.cpp
===
--- clang/test/Index/print-type-size.cpp
+++ clang/test/Index/print-type-size.cpp
@@ -391,6 +391,10 @@
 Foo t1;
 Foo t2;
 
+class BrowsingContext {
+  auto Tie(void*) const;
+};
+
 void c;
 
 plopplop;
Index: clang/include/clang-c/Index.h
===
--- clang/include/clang-c/Index.h
+++ clang/include/clang-c/Index.h
@@ -3839,7 +3839,11 @@
   /**
* The Field name is not valid for this record.
*/
-  CXTypeLayoutError_InvalidFieldName = -5
+  CXTypeLayoutError_InvalidFieldName = -5,
+  /**
+   * The type is undeduced.
+   */
+  CXTypeLayoutError_Undeduced = -6
 };
 
 /**
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58570: [libclang] Expose warn_unused and warn_unused_result attributes.

2019-02-22 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio created this revision.
emilio added reviewers: arphaman, Anastasia.
Herald added subscribers: cfe-commits, JDevlieghere.
Herald added a project: clang.

This is helpful to properly detect them, and fixing issues like
https://github.com/rust-lang/rust-bindgen/issues/1518.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D58570

Files:
  clang/include/clang-c/Index.h
  clang/test/Index/attributes.c
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp


Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -79,6 +79,8 @@
 case attr::ObjCBoxable: return CXCursor_ObjCBoxable;
 case attr::FlagEnum: return CXCursor_FlagEnum;
 case attr::Convergent: return CXCursor_ConvergentAttr;
+case attr::WarnUnused: return CXCursor_WarnUnusedAttr;
+case attr::WarnUnusedResult: return CXCursor_WarnUnusedResultAttr;
   }
 
   return CXCursor_UnexposedAttr;
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -5477,6 +5477,10 @@
   return cxstring::createRef("FriendDecl");
   case CXCursor_ConvergentAttr:
   return cxstring::createRef("attribute(convergent)");
+  case CXCursor_WarnUnusedAttr:
+  return cxstring::createRef("attribute(warn_unused)");
+  case CXCursor_WarnUnusedResultAttr:
+  return cxstring::createRef("attribute(warn_unused_result)");
   }
 
   llvm_unreachable("Unhandled CXCursorKind");
Index: clang/test/Index/attributes.c
===
--- clang/test/Index/attributes.c
+++ clang/test/Index/attributes.c
@@ -14,6 +14,12 @@
 
 void convergent_fn() __attribute__((convergent));
 
+int warn_unused_result_fn() __attribute__((warn_unused_result));
+
+struct __attribute__((warn_unused)) WarnUnused {
+  int b;
+};
+
 // CHECK: attributes.c:3:32: StructDecl=Test2:3:32 (Definition) Extent=[3:1 - 
5:2]
 // CHECK: attributes.c:3:23: attribute(packed)=packed Extent=[3:23 - 3:29]
 // CHECK: attributes.c:4:8: FieldDecl=a:4:8 (Definition) Extent=[4:3 - 4:9] 
[access=public]
@@ -29,3 +35,7 @@
 // CHECK: attributes.c:12:3: EnumConstantDecl=Foo:12:3 (Definition) 
Extent=[12:3 - 12:6]
 // CHECK: attributes.c:15:6: FunctionDecl=convergent_fn:15:6 Extent=[15:1 - 
15:49]
 // CHECK: attributes.c:15:37: attribute(convergent)= Extent=[15:37 - 15:47]
+// CHECK: attributes.c:17:5: FunctionDecl=warn_unused_result_fn:17:5 
Extent=[17:1 - 17:64]
+// CHECK: attributes.c:17:44: attribute(warn_unused_result)= Extent=[17:44 - 
17:62]
+// CHECK: attributes.c:19:37: StructDecl=WarnUnused:19:37 (Definition) 
Extent=[19:1 - 21:2]
+// CHECK: attributes.c:19:23: attribute(warn_unused)= Extent=[19:23 - 19:34]
Index: clang/include/clang-c/Index.h
===
--- clang/include/clang-c/Index.h
+++ clang/include/clang-c/Index.h
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 51
+#define CINDEX_VERSION_MINOR 52
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -2587,7 +2587,9 @@
   CXCursor_ObjCBoxable   = 436,
   CXCursor_FlagEnum  = 437,
   CXCursor_ConvergentAttr= 438,
-  CXCursor_LastAttr  = CXCursor_ConvergentAttr,
+  CXCursor_WarnUnusedAttr= 439,
+  CXCursor_WarnUnusedResultAttr  = 440,
+  CXCursor_LastAttr  = CXCursor_WarnUnusedResultAttr,
 
   /* Preprocessing */
   CXCursor_PreprocessingDirective= 500,


Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -79,6 +79,8 @@
 case attr::ObjCBoxable: return CXCursor_ObjCBoxable;
 case attr::FlagEnum: return CXCursor_FlagEnum;
 case attr::Convergent: return CXCursor_ConvergentAttr;
+case attr::WarnUnused: return CXCursor_WarnUnusedAttr;
+case attr::WarnUnusedResult: return CXCursor_WarnUnusedResultAttr;
   }
 
   return CXCursor_UnexposedAttr;
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -5477,6 +5477,10 @@
   return cxstring::createRef("FriendDecl");
   case CXCursor_ConvergentAttr:
   return cxstring::createRef("attribute(convergent)");
+  case CXCursor_WarnUnusedAttr:
+  return cxstring::createRef("attribute(warn_unused)");
+  case CXCursor_WarnUnusedResultAttr:
+  return cxstring::createRef("attribute(warn_unused_result)");
   }
 
   llvm_unreachable("Unhandled CXCursorKind");
In

[PATCH] D58571: [libclang] Fix a trivial error introduced in D57946.

2019-02-22 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio created this revision.
emilio added reviewers: Anastasia, arphaman.
Herald added a reviewer: serge-sans-paille.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The value for CXCursor_ConvergentAttr is not 420. I'm not really sure how easy
it is to test this, and I'm not familiar with the python bindings, just noticed
the error while looking at D57946  to write 
D58570 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D58571

Files:
  clang/bindings/python/clang/cindex.py


Index: clang/bindings/python/clang/cindex.py
===
--- clang/bindings/python/clang/cindex.py
+++ clang/bindings/python/clang/cindex.py
@@ -1342,7 +1342,7 @@
 
 CursorKind.DLLEXPORT_ATTR = CursorKind(418)
 CursorKind.DLLIMPORT_ATTR = CursorKind(419)
-CursorKind.CONVERGENT_ATTR = CursorKind(420)
+CursorKind.CONVERGENT_ATTR = CursorKind(438)
 
 ###
 # Preprocessing


Index: clang/bindings/python/clang/cindex.py
===
--- clang/bindings/python/clang/cindex.py
+++ clang/bindings/python/clang/cindex.py
@@ -1342,7 +1342,7 @@
 
 CursorKind.DLLEXPORT_ATTR = CursorKind(418)
 CursorKind.DLLIMPORT_ATTR = CursorKind(419)
-CursorKind.CONVERGENT_ATTR = CursorKind(420)
+CursorKind.CONVERGENT_ATTR = CursorKind(438)
 
 ###
 # Preprocessing
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58569: [libclang] Avoid crashing when getting layout info of an undeduced type.

2019-02-25 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio marked 2 inline comments as done.
emilio added inline comments.



Comment at: clang/tools/c-index-test/c-index-test.c:1695
+CXType RT = clang_getResultType(T);
+if (RT.kind != CXType_Invalid)
+  PrintSingleTypeSize(RT, " [resulttype=%s] [resulttypekind=%s]",

Anastasia wrote:
> Should it not return undeduced error in the other case?
I'm not sure what you mean, can you clarify?

The undeduced error is only returned when you try to access the `Auto` type 
which is the return value, not the function type, which has a known layout.

So in the error case, `T` here is the `auto Tie(void*) const;` type, and `RT` 
is the undeduced `auto` type, which is what crashed.

We had no way to exercise this in `c-index-test`, so I changed it to exercise 
this codepath too. I can add a `CHECK` for the error code if you want.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58569/new/

https://reviews.llvm.org/D58569



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64409: [libclang] Fix hang in release / assertion in debug when evaluating value-dependent types.

2019-07-09 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio created this revision.
emilio added reviewers: Anastasia, arphaman.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.
emilio edited the summary of this revision.

Expression evaluator doesn't work in value-dependent types, so ensure that the
precondition it asserts holds.

This fixes https://bugs.llvm.org/show_bug.cgi?id=42532.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64409

Files:
  clang/test/Index/evaluate-cursor.cpp
  clang/tools/libclang/CIndex.cpp


Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -3782,6 +3782,8 @@
 return nullptr;
 
   expr = expr->IgnoreParens();
+  if (expr->isValueDependent())
+return nullptr;
   if (!expr->EvaluateAsRValue(ER, ctx))
 return nullptr;
 
Index: clang/test/Index/evaluate-cursor.cpp
===
--- clang/test/Index/evaluate-cursor.cpp
+++ clang/test/Index/evaluate-cursor.cpp
@@ -21,6 +21,11 @@
 
 long long HUGE_NEG = -(1ll << 35);
 
+template  class e {
+  using f = d;
+  static const auto g = alignof(f);
+};
+
 // RUN: c-index-test -evaluate-cursor-at=%s:4:7 \
 // RUN:-evaluate-cursor-at=%s:8:7 \
 // RUN:-evaluate-cursor-at=%s:8:11 -std=c++11 %s | FileCheck %s
@@ -42,3 +47,9 @@
 // CHECK-LONG: unsigned, Value: 1152921504606846976
 // CHECK-LONG: unsigned, Value: 9223372036854775808
 // CHECK-LONG: Value: -34359738368
+
+// RUN: c-index-test -evaluate-cursor-at=%s:18:20 \
+// RUN:-evaluate-cursor-at=%s:20:20 \
+// RUN:-evaluate-cursor-at=%s:26:21 \
+// RUN:-std=c++11 %s | FileCheck -check-prefix=CHECK-DOES-NOT-CRASH %s
+// CHECK-DOES-NOT-CRASH: Not Evaluatable


Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -3782,6 +3782,8 @@
 return nullptr;
 
   expr = expr->IgnoreParens();
+  if (expr->isValueDependent())
+return nullptr;
   if (!expr->EvaluateAsRValue(ER, ctx))
 return nullptr;
 
Index: clang/test/Index/evaluate-cursor.cpp
===
--- clang/test/Index/evaluate-cursor.cpp
+++ clang/test/Index/evaluate-cursor.cpp
@@ -21,6 +21,11 @@
 
 long long HUGE_NEG = -(1ll << 35);
 
+template  class e {
+  using f = d;
+  static const auto g = alignof(f);
+};
+
 // RUN: c-index-test -evaluate-cursor-at=%s:4:7 \
 // RUN:-evaluate-cursor-at=%s:8:7 \
 // RUN:-evaluate-cursor-at=%s:8:11 -std=c++11 %s | FileCheck %s
@@ -42,3 +47,9 @@
 // CHECK-LONG: unsigned, Value: 1152921504606846976
 // CHECK-LONG: unsigned, Value: 9223372036854775808
 // CHECK-LONG: Value: -34359738368
+
+// RUN: c-index-test -evaluate-cursor-at=%s:18:20 \
+// RUN:-evaluate-cursor-at=%s:20:20 \
+// RUN:-evaluate-cursor-at=%s:26:21 \
+// RUN:-std=c++11 %s | FileCheck -check-prefix=CHECK-DOES-NOT-CRASH %s
+// CHECK-DOES-NOT-CRASH: Not Evaluatable
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64409: [libclang] Fix hang in release / assertion in debug when evaluating value-dependent types.

2019-07-09 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365490: [libclang] Fix hang in release / assertion in debug 
when evaluating value… (authored by emilio, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64409?vs=208658&id=208679#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64409/new/

https://reviews.llvm.org/D64409

Files:
  cfe/trunk/test/Index/evaluate-cursor.cpp
  cfe/trunk/tools/libclang/CIndex.cpp


Index: cfe/trunk/test/Index/evaluate-cursor.cpp
===
--- cfe/trunk/test/Index/evaluate-cursor.cpp
+++ cfe/trunk/test/Index/evaluate-cursor.cpp
@@ -21,6 +21,11 @@
 
 long long HUGE_NEG = -(1ll << 35);
 
+template  class e {
+  using f = d;
+  static const auto g = alignof(f);
+};
+
 // RUN: c-index-test -evaluate-cursor-at=%s:4:7 \
 // RUN:-evaluate-cursor-at=%s:8:7 \
 // RUN:-evaluate-cursor-at=%s:8:11 -std=c++11 %s | FileCheck %s
@@ -42,3 +47,9 @@
 // CHECK-LONG: unsigned, Value: 1152921504606846976
 // CHECK-LONG: unsigned, Value: 9223372036854775808
 // CHECK-LONG: Value: -34359738368
+
+// RUN: c-index-test -evaluate-cursor-at=%s:18:20 \
+// RUN:-evaluate-cursor-at=%s:20:20 \
+// RUN:-evaluate-cursor-at=%s:26:21 \
+// RUN:-std=c++11 %s | FileCheck -check-prefix=CHECK-DOES-NOT-CRASH %s
+// CHECK-DOES-NOT-CRASH: Not Evaluatable
Index: cfe/trunk/tools/libclang/CIndex.cpp
===
--- cfe/trunk/tools/libclang/CIndex.cpp
+++ cfe/trunk/tools/libclang/CIndex.cpp
@@ -3782,6 +3782,8 @@
 return nullptr;
 
   expr = expr->IgnoreParens();
+  if (expr->isValueDependent())
+return nullptr;
   if (!expr->EvaluateAsRValue(ER, ctx))
 return nullptr;
 


Index: cfe/trunk/test/Index/evaluate-cursor.cpp
===
--- cfe/trunk/test/Index/evaluate-cursor.cpp
+++ cfe/trunk/test/Index/evaluate-cursor.cpp
@@ -21,6 +21,11 @@
 
 long long HUGE_NEG = -(1ll << 35);
 
+template  class e {
+  using f = d;
+  static const auto g = alignof(f);
+};
+
 // RUN: c-index-test -evaluate-cursor-at=%s:4:7 \
 // RUN:-evaluate-cursor-at=%s:8:7 \
 // RUN:-evaluate-cursor-at=%s:8:11 -std=c++11 %s | FileCheck %s
@@ -42,3 +47,9 @@
 // CHECK-LONG: unsigned, Value: 1152921504606846976
 // CHECK-LONG: unsigned, Value: 9223372036854775808
 // CHECK-LONG: Value: -34359738368
+
+// RUN: c-index-test -evaluate-cursor-at=%s:18:20 \
+// RUN:-evaluate-cursor-at=%s:20:20 \
+// RUN:-evaluate-cursor-at=%s:26:21 \
+// RUN:-std=c++11 %s | FileCheck -check-prefix=CHECK-DOES-NOT-CRASH %s
+// CHECK-DOES-NOT-CRASH: Not Evaluatable
Index: cfe/trunk/tools/libclang/CIndex.cpp
===
--- cfe/trunk/tools/libclang/CIndex.cpp
+++ cfe/trunk/tools/libclang/CIndex.cpp
@@ -3782,6 +3782,8 @@
 return nullptr;
 
   expr = expr->IgnoreParens();
+  if (expr->isValueDependent())
+return nullptr;
   if (!expr->EvaluateAsRValue(ER, ctx))
 return nullptr;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64409: [libclang] Fix hang in release / assertion in debug when evaluating value-dependent types.

2019-07-09 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a comment.

Thanks for the review as always @Anastasia ^.^


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64409/new/

https://reviews.llvm.org/D64409



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72742: Don't assume promotable integers are zero/sign-extended already in x86-64 ABI.

2020-01-14 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio created this revision.
Herald added a reviewer: jdoerfert.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Sign-extension is not guaranteed by the ABI, and thus the callee cannot assume
it.

This fixes PR44228 and PR12207.

With these changes, there are still two tests that need updating:

- CodeGenObjC/optimized-setter.m fails with:

  clang: llvm/lib/IR/Instructions.cpp:400: void 
llvm::CallInst::init(llvm::FunctionType *, llvm::Value *, ArrayRef, ArrayRef, const llvm::Twine &): Assertion `(i >= 
FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && "Calling 
a function with a bad signature!"' failed.



- OpenMP/parallel_for_simd_codegen.cpp fails with:

  clang: clang/lib/CodeGen/CGCall.cpp:3858: clang::CodeGen::RValue 
clang::CodeGen::CodeGenFunction::EmitCall(const clang::CodeGen::CGFunctionInfo 
&, const clang::CodeGen::CGCallee &, clang::CodeGen::ReturnValueSlot, const 
clang::CodeGen::CallArgList &, llvm::CallBase **, clang::SourceLocation): 
Assertion `IRFuncTy == TypeFromVal' failed.

These two are probably bad assumptions in some of the ObjC / OpenMP-specific
code, but I want to check this patch is on the right track before digging more.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72742

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/2007-06-18-SextAttrAggregate.c
  clang/test/CodeGen/avx512-reduceMinMaxIntrin.c
  clang/test/CodeGen/catch-implicit-integer-sign-changes.c
  clang/test/CodeGen/function-attributes.c
  clang/test/CodeGen/regcall.c
  clang/test/CodeGen/x86_64-arguments-nacl.c
  clang/test/CodeGen/x86_64-arguments.c
  clang/test/CodeGenCXX/blocks.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/forward-enum.cpp
  clang/test/CodeGenCXX/value-init.cpp
  clang/test/CodeGenCXX/virtual-bases.cpp
  clang/test/CodeGenObjC/arc-blocks.m
  clang/test/CodeGenObjC/arc-literals.m
  clang/test/CodeGenObjC/arc-property.m
  clang/test/CodeGenObjC/arc-ternary-op.m
  clang/test/CodeGenObjC/atomic-aggregate-property.m
  clang/test/CodeGenObjC/objc-literal-tests.m
  clang/test/CodeGenObjC/objc_copyStruct.m
  clang/test/CodeGenObjC/property-atomic-bool.m
  clang/test/CodeGenObjCXX/property-object-reference-1.mm
  llvm/test/CodeGen/X86/x86-64-arg.ll

Index: llvm/test/CodeGen/X86/x86-64-arg.ll
===
--- llvm/test/CodeGen/X86/x86-64-arg.ll
+++ llvm/test/CodeGen/X86/x86-64-arg.ll
@@ -1,6 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
 ; RUN: llc < %s | FileCheck %s
-
 ; The input value is already sign extended, don't re-extend it.
 ; This testcase corresponds to:
 ;   int test(short X) { return (int)X; }
Index: clang/test/CodeGenObjCXX/property-object-reference-1.mm
===
--- clang/test/CodeGenObjCXX/property-object-reference-1.mm
+++ clang/test/CodeGenObjCXX/property-object-reference-1.mm
@@ -28,4 +28,6 @@
 // CHECK: store %struct.TCPPObject* [[cppObject:%.*]], %struct.TCPPObject** [[cppObjectaddr]], align 8
 // CHECK:  [[THREE:%.*]] = load %struct.TCPPObject*, %struct.TCPPObject** [[cppObjectaddr]], align 8
 // CHECK:  [[FOUR:%.*]] = bitcast %struct.TCPPObject* [[THREE]] to i8*
-// CHECK:  call void @objc_copyStruct(i8* [[TWO:%.*]], i8* [[FOUR]], i64 256, i1 zeroext true, i1 zeroext false)
+// CHECK:  [[FIVE:%.*]] = load i8, i8* %coerce, align 1
+// CHECK:  [[SIX:%.*]] = load i8, i8* %coerce1, align 1
+// CHECK:  call void @objc_copyStruct(i8* [[TWO:%.*]], i8* [[FOUR]], i64 256, i8 [[FIVE]], i8 [[SIX]])
Index: clang/test/CodeGenObjC/property-atomic-bool.m
===
--- clang/test/CodeGenObjC/property-atomic-bool.m
+++ clang/test/CodeGenObjC/property-atomic-bool.m
@@ -5,7 +5,7 @@
 // CHECK:   %[[TOBOOL:.*]] = trunc i8 %[[ATOMIC_LOAD]] to i1
 // CHECK:   ret i1 %[[TOBOOL]]
 
-// CHECK: define internal void @"\01-[A0 setP:]"({{.*}} i1 zeroext {{.*}})
+// CHECK: define internal void @"\01-[A0 setP:]"({{.*}} i8* {{.*}})
 // CHECK:   store atomic i8 %{{.*}}, i8* %{{.*}} seq_cst
 // CHECK:   ret void
 
@@ -14,7 +14,7 @@
 // CHECK:   %[[TOBOOL:.*]] = trunc i8 %load to i1
 // CHECK:   ret i1 %[[TOBOOL]]
 
-// CHECK: define internal void @"\01-[A1 setP:]"({{.*}} i1 zeroext %p)
+// CHECK: define internal void @"\01-[A1 setP:]"({{.*}} i8 %p.coerce)
 // CHECK:   store atomic i8 %{{.*}}, i8* %{{.*}} unordered
 // CHECK:   ret void
 
Index: clang/test/CodeGenObjC/objc_copyStruct.m
===
--- clang/test/CodeGenObjC/objc_copyStruct.m
+++ clang/test/CodeGenObjC/objc_copyStruct.m
@@ -1,5 +1,5 @@
-// RUN: %clang -target x86_64-unknown-windows-msvc -fobjc-runtime=ios -Wno-objc-root-class -S -o - -emit-llvm %s | FileCheck %s
-// RUN

[PATCH] D72742: Don't assume promotable integers are zero/sign-extended already in x86-64 ABI.

2020-01-15 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a comment.

The relevant discussion is here 
. From the "Parameter 
Passing" section in 
https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdf, there's no 
mention of sign-extension requirements for arguments.

> The only related thing is
>  "When a value of type _Bool is returned or passed in a register or on the 
> stack,
>  bit 0 contains the truth value and bits 1 to 7 shall be zero."
>  with a footnote:
>  "Other bits are left unspecified, hence the consumer side of those values 
> can rely on it being 0 or 1 when truncated to 8 bit."

which says that _Bool has only significant low 8 bits and the rest is 
unspecified.

Then Michael Matz (one of the editors of that document) clarifies below:

> Yes, we (intentionally) haven't required any extensions to happen for 
> arguments

or return values smaller than 64bit (e.g. we haven't even specified that 
arguments <= 32bit would be zero-extended in the high bits, as would have been
natural with the instruction set).  If LLVM relies on that it would be a bug.

There's more information on that bug and related ones, but I think the above 
should be enough :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72742/new/

https://reviews.llvm.org/D72742



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72742: Don't assume promotable integers are zero/sign-extended already in x86-64 ABI.

2020-01-15 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a comment.

In D72742#1822554 , @rnk wrote:

> +@chandlerc @rjmccall
>
> Didn't we work this out already when John added the alignment tracking stuff? 
> I remember this bug involving libjpegturbo standalone assembly receiving a 
> 32-bit argument, and then using the full 64-bit RDI register to read it, but 
> clang stopped zero extending it. I thought the ABI doc was ambiguous at the 
> time, and we studied GCC's behavior, and that is how we arrived at clang's 
> current behavior. I am generally skeptical about changing behavior in this 
> area just because the ABI doc says something now. It keeps changing. What did 
> it say in the past? Shouldn't we pay more attention to that?
>
> Found the libjpegturbo thing:
>  
> https://github.com/libjpeg-turbo/libjpeg-turbo/commit/498d9bc92fcf39124b6f08e57326944dedd2ddd6


That seems somewhat related. This would be a similar change to the one that 
clang did back then, but for the bytes in the lower 32-bits when the argument 
is smaller than that.

The ABI document, afaict, has never defined the inputs to be zero-extended. See 
https://groups.google.com/forum/?hl=en#!topic/x86-64-abi/E8O33onbnGQ for an old 
thread discussing this, and the two bugs that are referenced in the commit 
message (one of them fairly old).

GCC does avoid the zero-extension on the caller sometimes, when not required by 
the language and when its optimizer finds it suitable.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72742/new/

https://reviews.llvm.org/D72742



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72742: Don't assume promotable integers are zero/sign-extended already in x86-64 ABI.

2020-02-03 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a comment.

Could anyone update me with how do they want me to proceed here? Is fixing the 
coercions enough to allow this to land? Do I need to make it target-specific? 
If so, which targets should keep the current behavior?

Another slightly more backwards-compatible alternative (though hacky, arguably) 
is to just not use the zext for optimization purposes in the backend. This 
would be simpler and should keep clang always sign-extending on the caller too, 
for now. We could then after a while, switch to this approach. D71178 
 contains such a patch, for comparison.

Thoughts?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72742/new/

https://reviews.llvm.org/D72742



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140074: [libclang] Remove redundant return statements in CXType.cpp

2023-02-28 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio updated this revision to Diff 501269.
emilio added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140074/new/

https://reviews.llvm.org/D140074

Files:
  clang/tools/libclang/CXType.cpp


Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -322,8 +322,6 @@
   QualType T = TD->getUnderlyingType();
   return MakeCXType(T, TU);
 }
-
-return MakeCXType(QualType(), TU);
   }
 
   return MakeCXType(QualType(), TU);
@@ -340,8 +338,6 @@
   QualType T = TD->getIntegerType();
   return MakeCXType(T, TU);
 }
-
-return MakeCXType(QualType(), TU);
   }
 
   return MakeCXType(QualType(), TU);
@@ -356,8 +352,6 @@
 if (const EnumConstantDecl *TD = dyn_cast_or_null(D)) {
   return TD->getInitVal().getSExtValue();
 }
-
-return LLONG_MIN;
   }
 
   return LLONG_MIN;
@@ -372,8 +366,6 @@
 if (const EnumConstantDecl *TD = dyn_cast_or_null(D)) {
   return TD->getInitVal().getZExtValue();
 }
-
-return ULLONG_MAX;
   }
 
   return ULLONG_MAX;


Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -322,8 +322,6 @@
   QualType T = TD->getUnderlyingType();
   return MakeCXType(T, TU);
 }
-
-return MakeCXType(QualType(), TU);
   }
 
   return MakeCXType(QualType(), TU);
@@ -340,8 +338,6 @@
   QualType T = TD->getIntegerType();
   return MakeCXType(T, TU);
 }
-
-return MakeCXType(QualType(), TU);
   }
 
   return MakeCXType(QualType(), TU);
@@ -356,8 +352,6 @@
 if (const EnumConstantDecl *TD = dyn_cast_or_null(D)) {
   return TD->getInitVal().getSExtValue();
 }
-
-return LLONG_MIN;
   }
 
   return LLONG_MIN;
@@ -372,8 +366,6 @@
 if (const EnumConstantDecl *TD = dyn_cast_or_null(D)) {
   return TD->getInitVal().getZExtValue();
 }
-
-return ULLONG_MAX;
   }
 
   return ULLONG_MAX;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140075: [libclang] Expose using shadow types and declarations in libclang.

2023-02-28 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio updated this revision to Diff 501270.
emilio added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140075/new/

https://reviews.llvm.org/D140075

Files:
  clang/include/clang-c/Index.h
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/Index/print-type.cpp
  clang/tools/libclang/CXCursor.cpp
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -100,6 +100,7 @@
 TKCASE(Record);
 TKCASE(Enum);
 TKCASE(Typedef);
+TKCASE(Using);
 TKCASE(ObjCInterface);
 TKCASE(ObjCObject);
 TKCASE(ObjCObjectPointer);
@@ -221,24 +222,9 @@
   return std::nullopt;
 }
 
-CXType clang_getCursorType(CXCursor C) {
-  using namespace cxcursor;
-
-  CXTranslationUnit TU = cxcursor::getCursorTU(C);
-  if (!TU)
-return MakeCXType(QualType(), TU);
-
-  ASTContext &Context = cxtu::getASTUnit(TU)->getASTContext();
-  if (clang_isExpression(C.kind)) {
-QualType T = cxcursor::getCursorExpr(C)->getType();
-return MakeCXType(T, TU);
-  }
-
-  if (clang_isDeclaration(C.kind)) {
-const Decl *D = cxcursor::getCursorDecl(C);
+static CXType getDeclType(const Decl* D, CXTranslationUnit TU, ASTContext &Context) {
 if (!D)
   return MakeCXType(QualType(), TU);
-
 if (const TypeDecl *TD = dyn_cast(D))
   return MakeCXType(Context.getTypeDeclType(TD), TU);
 if (const ObjCInterfaceDecl *ID = dyn_cast(D))
@@ -251,9 +237,27 @@
   return MakeCXType(PD->getType(), TU);
 if (const FunctionTemplateDecl *FTD = dyn_cast(D))
   return MakeCXType(FTD->getTemplatedDecl()->getType(), TU);
+if (const auto *UD = dyn_cast(D))
+  return getDeclType(UD->getTargetDecl(), TU, Context);
 return MakeCXType(QualType(), TU);
+}
+
+CXType clang_getCursorType(CXCursor C) {
+  using namespace cxcursor;
+
+  CXTranslationUnit TU = cxcursor::getCursorTU(C);
+  if (!TU)
+return MakeCXType(QualType(), TU);
+
+  ASTContext &Context = cxtu::getASTUnit(TU)->getASTContext();
+  if (clang_isExpression(C.kind)) {
+QualType T = cxcursor::getCursorExpr(C)->getType();
+return MakeCXType(T, TU);
   }
 
+  if (clang_isDeclaration(C.kind))
+return getDeclType(cxcursor::getCursorDecl(C), TU, Context);
+
   if (clang_isReference(C.kind)) {
 switch (C.kind) {
 case CXCursor_ObjCSuperClassRef: {
@@ -503,6 +507,9 @@
   case Type::Typedef:
 D = cast(TP)->getDecl();
 break;
+  case Type::Using:
+D = cast(TP)->getFoundDecl();
+break;
   case Type::ObjCObject:
 D = cast(TP)->getInterface();
 break;
@@ -600,6 +607,7 @@
 TKIND(Record);
 TKIND(Enum);
 TKIND(Typedef);
+TKIND(Using);
 TKIND(ObjCInterface);
 TKIND(ObjCObject);
 TKIND(ObjCObjectPointer);
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -1276,6 +1276,10 @@
 return MakeCursorTypeRef(Tag->getDecl(), Loc, TU);
   if (const TemplateTypeParmType *TemplP = Ty->getAs())
 return MakeCursorTypeRef(TemplP->getDecl(), Loc, TU);
+  if (const UsingType *Using = Ty->getAs())
+if (const UsingShadowDecl *Shadow = Using->getFoundDecl())
+  if (const auto *TD = dyn_cast_or_null(Shadow->getTargetDecl()))
+return MakeCursorTypeRef(TD, Loc, TU);
 
   return cursor;
 }
Index: clang/test/Index/print-type.cpp
===
--- clang/test/Index/print-type.cpp
+++ clang/test/Index/print-type.cpp
@@ -92,6 +92,14 @@
 }
 
 inline namespace InlineNS {}
+
+namespace ToBeExported {
+  typedef int ToBeExportedType;
+}
+
+using ToBeExported::ToBeExportedType;
+void UseToBeExported(ToBeExportedType f);
+
 // 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]
@@ -207,3 +215,5 @@
 // CHECK: EnumDecl=(unnamed enum at {{.*}}:87:3 (Definition) [type=X::(unnamed enum at {{.*}}print-type.cpp:87:3)] [typekind=Enum] [isPOD=1] [isAnon=1]
 // CHECK: Namespace=:90:11 (Definition) [type=] [typekind=Invalid] [isPOD=0] [isAnon=1]
 // CHECK: Namespace=InlineNS:94:18 (Definition) [type=] [typekind=Invalid] [isPOD=0] [isAnonRecDecl=0] [isInlineNamespace=1]
+// CHECK: UsingDeclaration=ToBeExportedType[97:15] [type=] [typekind=Invalid] [isPOD=0] [isAnonRecDecl=0]
+// CHECK: ParmDecl=f:101:39 (Definition) [type=ToBeExportedType] [typekind=Elaborated] [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1] [isAnonRecDecl=0]
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -4062,6 +

[PATCH] D140074: [libclang] Remove redundant return statements in CXType.cpp

2023-02-28 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a comment.

In D140074#4159583 , 
@serge-sans-paille wrote:

> The cleanup looks good to me, thanks! Out of curiosity, did just stumble on 
> this, or did an automatic tool gave you an hint?

I was just reading through the code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140074/new/

https://reviews.llvm.org/D140074

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140074: [libclang] Remove redundant return statements in CXType.cpp

2022-12-14 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio created this revision.
Herald added a project: All.
emilio requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Let the branch fall through the error path like other functions here do.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140074

Files:
  clang/tools/libclang/CXType.cpp


Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -324,8 +324,6 @@
   QualType T = TD->getUnderlyingType();
   return MakeCXType(T, TU);
 }
-
-return MakeCXType(QualType(), TU);
   }
 
   return MakeCXType(QualType(), TU);
@@ -342,10 +340,7 @@
   QualType T = TD->getIntegerType();
   return MakeCXType(T, TU);
 }
-
-return MakeCXType(QualType(), TU);
   }
-
   return MakeCXType(QualType(), TU);
 }
 
@@ -354,14 +349,10 @@
 
   if (clang_isDeclaration(C.kind)) {
 const Decl *D = cxcursor::getCursorDecl(C);
-
 if (const EnumConstantDecl *TD = dyn_cast_or_null(D)) {
   return TD->getInitVal().getSExtValue();
 }
-
-return LLONG_MIN;
   }
-
   return LLONG_MIN;
 }
 
@@ -374,10 +365,7 @@
 if (const EnumConstantDecl *TD = dyn_cast_or_null(D)) {
   return TD->getInitVal().getZExtValue();
 }
-
-return ULLONG_MAX;
   }
-
   return ULLONG_MAX;
 }
 


Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -324,8 +324,6 @@
   QualType T = TD->getUnderlyingType();
   return MakeCXType(T, TU);
 }
-
-return MakeCXType(QualType(), TU);
   }
 
   return MakeCXType(QualType(), TU);
@@ -342,10 +340,7 @@
   QualType T = TD->getIntegerType();
   return MakeCXType(T, TU);
 }
-
-return MakeCXType(QualType(), TU);
   }
-
   return MakeCXType(QualType(), TU);
 }
 
@@ -354,14 +349,10 @@
 
   if (clang_isDeclaration(C.kind)) {
 const Decl *D = cxcursor::getCursorDecl(C);
-
 if (const EnumConstantDecl *TD = dyn_cast_or_null(D)) {
   return TD->getInitVal().getSExtValue();
 }
-
-return LLONG_MIN;
   }
-
   return LLONG_MIN;
 }
 
@@ -374,10 +365,7 @@
 if (const EnumConstantDecl *TD = dyn_cast_or_null(D)) {
   return TD->getInitVal().getZExtValue();
 }
-
-return ULLONG_MAX;
   }
-
   return ULLONG_MAX;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140074: [libclang] Remove redundant return statements in CXType.cpp

2022-12-14 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio updated this revision to Diff 483048.
emilio added a comment.

Remove gratuitious whitespace changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140074/new/

https://reviews.llvm.org/D140074

Files:
  clang/tools/libclang/CXType.cpp


Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -324,8 +324,6 @@
   QualType T = TD->getUnderlyingType();
   return MakeCXType(T, TU);
 }
-
-return MakeCXType(QualType(), TU);
   }
 
   return MakeCXType(QualType(), TU);
@@ -342,8 +340,6 @@
   QualType T = TD->getIntegerType();
   return MakeCXType(T, TU);
 }
-
-return MakeCXType(QualType(), TU);
   }
 
   return MakeCXType(QualType(), TU);
@@ -358,8 +354,6 @@
 if (const EnumConstantDecl *TD = dyn_cast_or_null(D)) {
   return TD->getInitVal().getSExtValue();
 }
-
-return LLONG_MIN;
   }
 
   return LLONG_MIN;
@@ -374,8 +368,6 @@
 if (const EnumConstantDecl *TD = dyn_cast_or_null(D)) {
   return TD->getInitVal().getZExtValue();
 }
-
-return ULLONG_MAX;
   }
 
   return ULLONG_MAX;


Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -324,8 +324,6 @@
   QualType T = TD->getUnderlyingType();
   return MakeCXType(T, TU);
 }
-
-return MakeCXType(QualType(), TU);
   }
 
   return MakeCXType(QualType(), TU);
@@ -342,8 +340,6 @@
   QualType T = TD->getIntegerType();
   return MakeCXType(T, TU);
 }
-
-return MakeCXType(QualType(), TU);
   }
 
   return MakeCXType(QualType(), TU);
@@ -358,8 +354,6 @@
 if (const EnumConstantDecl *TD = dyn_cast_or_null(D)) {
   return TD->getInitVal().getSExtValue();
 }
-
-return LLONG_MIN;
   }
 
   return LLONG_MIN;
@@ -374,8 +368,6 @@
 if (const EnumConstantDecl *TD = dyn_cast_or_null(D)) {
   return TD->getInitVal().getZExtValue();
 }
-
-return ULLONG_MAX;
   }
 
   return ULLONG_MAX;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140074: [libclang] Remove redundant return statements in CXType.cpp

2022-12-14 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a reviewer: aaron.ballman.
emilio added a comment.

Unclear to me who to request review from, so I'm peeking reviewer based on the 
git log. Please feel free to review or forward to someone else as appropriate. 
Thanks in advance!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140074/new/

https://reviews.llvm.org/D140074

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140075: [libclang] Expose using shadow types and declarations in libclang.

2022-12-14 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio created this revision.
Herald added subscribers: arphaman, JDevlieghere.
Herald added a project: All.
emilio requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This allows tools like rust-bindgen to detect typedefs properly.

See https://github.com/rust-lang/rust-bindgen/pull/2372 (which relies on
this patch) for an example.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140075

Files:
  clang/include/clang-c/Index.h
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/Index/print-type.cpp
  clang/tools/libclang/CXCursor.cpp
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -99,6 +99,7 @@
 TKCASE(Record);
 TKCASE(Enum);
 TKCASE(Typedef);
+TKCASE(Using);
 TKCASE(ObjCInterface);
 TKCASE(ObjCObject);
 TKCASE(ObjCObjectPointer);
@@ -219,24 +220,9 @@
   return std::nullopt;
 }
 
-CXType clang_getCursorType(CXCursor C) {
-  using namespace cxcursor;
-
-  CXTranslationUnit TU = cxcursor::getCursorTU(C);
-  if (!TU)
-return MakeCXType(QualType(), TU);
-
-  ASTContext &Context = cxtu::getASTUnit(TU)->getASTContext();
-  if (clang_isExpression(C.kind)) {
-QualType T = cxcursor::getCursorExpr(C)->getType();
-return MakeCXType(T, TU);
-  }
-
-  if (clang_isDeclaration(C.kind)) {
-const Decl *D = cxcursor::getCursorDecl(C);
+static CXType getDeclType(const Decl* D, CXTranslationUnit TU, ASTContext &Context) {
 if (!D)
   return MakeCXType(QualType(), TU);
-
 if (const TypeDecl *TD = dyn_cast(D))
   return MakeCXType(Context.getTypeDeclType(TD), TU);
 if (const ObjCInterfaceDecl *ID = dyn_cast(D))
@@ -249,9 +235,27 @@
   return MakeCXType(PD->getType(), TU);
 if (const FunctionTemplateDecl *FTD = dyn_cast(D))
   return MakeCXType(FTD->getTemplatedDecl()->getType(), TU);
+if (const auto *UD = dyn_cast(D))
+  return getDeclType(UD->getTargetDecl(), TU, Context);
 return MakeCXType(QualType(), TU);
+}
+
+CXType clang_getCursorType(CXCursor C) {
+  using namespace cxcursor;
+
+  CXTranslationUnit TU = cxcursor::getCursorTU(C);
+  if (!TU)
+return MakeCXType(QualType(), TU);
+
+  ASTContext &Context = cxtu::getASTUnit(TU)->getASTContext();
+  if (clang_isExpression(C.kind)) {
+QualType T = cxcursor::getCursorExpr(C)->getType();
+return MakeCXType(T, TU);
   }
 
+  if (clang_isDeclaration(C.kind))
+return getDeclType(cxcursor::getCursorDecl(C), TU, Context);
+
   if (clang_isReference(C.kind)) {
 switch (C.kind) {
 case CXCursor_ObjCSuperClassRef: {
@@ -501,6 +505,9 @@
   case Type::Typedef:
 D = cast(TP)->getDecl();
 break;
+  case Type::Using:
+D = cast(TP)->getFoundDecl();
+break;
   case Type::ObjCObject:
 D = cast(TP)->getInterface();
 break;
@@ -598,6 +605,7 @@
 TKIND(Record);
 TKIND(Enum);
 TKIND(Typedef);
+TKIND(Using);
 TKIND(ObjCInterface);
 TKIND(ObjCObject);
 TKIND(ObjCObjectPointer);
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -1276,6 +1276,10 @@
 return MakeCursorTypeRef(Tag->getDecl(), Loc, TU);
   if (const TemplateTypeParmType *TemplP = Ty->getAs())
 return MakeCursorTypeRef(TemplP->getDecl(), Loc, TU);
+  if (const UsingType *Using = Ty->getAs())
+if (const UsingShadowDecl *Shadow = Using->getFoundDecl())
+  if (const auto *TD = dyn_cast_or_null(Shadow->getTargetDecl()))
+return MakeCursorTypeRef(TD, Loc, TU);
 
   return cursor;
 }
Index: clang/test/Index/print-type.cpp
===
--- clang/test/Index/print-type.cpp
+++ clang/test/Index/print-type.cpp
@@ -92,6 +92,14 @@
 }
 
 inline namespace InlineNS {}
+
+namespace ToBeExported {
+  typedef int ToBeExportedType;
+}
+
+using ToBeExported::ToBeExportedType;
+void UseToBeExported(ToBeExportedType f);
+
 // 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]
@@ -207,3 +215,5 @@
 // CHECK: EnumDecl=(unnamed enum at {{.*}}:87:3 (Definition) [type=X::(unnamed enum at {{.*}}print-type.cpp:87:3)] [typekind=Enum] [isPOD=1] [isAnon=1]
 // CHECK: Namespace=:90:11 (Definition) [type=] [typekind=Invalid] [isPOD=0] [isAnon=1]
 // CHECK: Namespace=InlineNS:94:18 (Definition) [type=] [typekind=Invalid] [isPOD=0] [isAnonRecDecl=0] [isInlineNamespace=1]
+// CHECK: UsingDeclaration=ToBeExportedType[97:9] [type=] [typekind=Invalid] [isPOD=0] [isAnonRecDecl=0]
+// CHECK: ParmDecl=f:101:39 (Definition) [type=ToBeExportedType] [typekind=Elaborated] [canonicaltype=int] [canonicalty

[PATCH] D140075: [libclang] Expose using shadow types and declarations in libclang.

2022-12-14 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a reviewer: aaron.ballman.
emilio added a comment.

(As in my previous commit, peeking based on git log, please review / forward as 
appropriate. Thanks again!)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140075/new/

https://reviews.llvm.org/D140075

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140075: [libclang] Expose using shadow types and declarations in libclang.

2022-12-16 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio updated this revision to Diff 483499.
emilio added a comment.

Fix test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140075/new/

https://reviews.llvm.org/D140075

Files:
  clang/include/clang-c/Index.h
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/Index/print-type.cpp
  clang/tools/libclang/CXCursor.cpp
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -99,6 +99,7 @@
 TKCASE(Record);
 TKCASE(Enum);
 TKCASE(Typedef);
+TKCASE(Using);
 TKCASE(ObjCInterface);
 TKCASE(ObjCObject);
 TKCASE(ObjCObjectPointer);
@@ -219,24 +220,9 @@
   return std::nullopt;
 }
 
-CXType clang_getCursorType(CXCursor C) {
-  using namespace cxcursor;
-
-  CXTranslationUnit TU = cxcursor::getCursorTU(C);
-  if (!TU)
-return MakeCXType(QualType(), TU);
-
-  ASTContext &Context = cxtu::getASTUnit(TU)->getASTContext();
-  if (clang_isExpression(C.kind)) {
-QualType T = cxcursor::getCursorExpr(C)->getType();
-return MakeCXType(T, TU);
-  }
-
-  if (clang_isDeclaration(C.kind)) {
-const Decl *D = cxcursor::getCursorDecl(C);
+static CXType getDeclType(const Decl* D, CXTranslationUnit TU, ASTContext &Context) {
 if (!D)
   return MakeCXType(QualType(), TU);
-
 if (const TypeDecl *TD = dyn_cast(D))
   return MakeCXType(Context.getTypeDeclType(TD), TU);
 if (const ObjCInterfaceDecl *ID = dyn_cast(D))
@@ -249,9 +235,27 @@
   return MakeCXType(PD->getType(), TU);
 if (const FunctionTemplateDecl *FTD = dyn_cast(D))
   return MakeCXType(FTD->getTemplatedDecl()->getType(), TU);
+if (const auto *UD = dyn_cast(D))
+  return getDeclType(UD->getTargetDecl(), TU, Context);
 return MakeCXType(QualType(), TU);
+}
+
+CXType clang_getCursorType(CXCursor C) {
+  using namespace cxcursor;
+
+  CXTranslationUnit TU = cxcursor::getCursorTU(C);
+  if (!TU)
+return MakeCXType(QualType(), TU);
+
+  ASTContext &Context = cxtu::getASTUnit(TU)->getASTContext();
+  if (clang_isExpression(C.kind)) {
+QualType T = cxcursor::getCursorExpr(C)->getType();
+return MakeCXType(T, TU);
   }
 
+  if (clang_isDeclaration(C.kind))
+return getDeclType(cxcursor::getCursorDecl(C), TU, Context);
+
   if (clang_isReference(C.kind)) {
 switch (C.kind) {
 case CXCursor_ObjCSuperClassRef: {
@@ -501,6 +505,9 @@
   case Type::Typedef:
 D = cast(TP)->getDecl();
 break;
+  case Type::Using:
+D = cast(TP)->getFoundDecl();
+break;
   case Type::ObjCObject:
 D = cast(TP)->getInterface();
 break;
@@ -598,6 +605,7 @@
 TKIND(Record);
 TKIND(Enum);
 TKIND(Typedef);
+TKIND(Using);
 TKIND(ObjCInterface);
 TKIND(ObjCObject);
 TKIND(ObjCObjectPointer);
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -1276,6 +1276,10 @@
 return MakeCursorTypeRef(Tag->getDecl(), Loc, TU);
   if (const TemplateTypeParmType *TemplP = Ty->getAs())
 return MakeCursorTypeRef(TemplP->getDecl(), Loc, TU);
+  if (const UsingType *Using = Ty->getAs())
+if (const UsingShadowDecl *Shadow = Using->getFoundDecl())
+  if (const auto *TD = dyn_cast_or_null(Shadow->getTargetDecl()))
+return MakeCursorTypeRef(TD, Loc, TU);
 
   return cursor;
 }
Index: clang/test/Index/print-type.cpp
===
--- clang/test/Index/print-type.cpp
+++ clang/test/Index/print-type.cpp
@@ -92,6 +92,14 @@
 }
 
 inline namespace InlineNS {}
+
+namespace ToBeExported {
+  typedef int ToBeExportedType;
+}
+
+using ToBeExported::ToBeExportedType;
+void UseToBeExported(ToBeExportedType f);
+
 // 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]
@@ -207,3 +215,5 @@
 // CHECK: EnumDecl=(unnamed enum at {{.*}}:87:3 (Definition) [type=X::(unnamed enum at {{.*}}print-type.cpp:87:3)] [typekind=Enum] [isPOD=1] [isAnon=1]
 // CHECK: Namespace=:90:11 (Definition) [type=] [typekind=Invalid] [isPOD=0] [isAnon=1]
 // CHECK: Namespace=InlineNS:94:18 (Definition) [type=] [typekind=Invalid] [isPOD=0] [isAnonRecDecl=0] [isInlineNamespace=1]
+// CHECK: UsingDeclaration=ToBeExportedType[97:15] [type=] [typekind=Invalid] [isPOD=0] [isAnonRecDecl=0]
+// CHECK: ParmDecl=f:101:39 (Definition) [type=ToBeExportedType] [typekind=Elaborated] [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1] [isAnonRecDecl=0]
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -4062,6 +

[PATCH] D32348: [libclang] Check for a record declaration before a template specialization.

2017-04-21 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio created this revision.
emilio added a project: clang-c.

This allows us to see the default template parameters too.

This is a regression in clang 4.0, so uplifting to a dot release would be neat 
(but not required, I guess).

The regression was caused by https://reviews.llvm.org/D26663.

Fixes bug 32539 (https://bugs.llvm.org//show_bug.cgi?id=32539).


Repository:
  rL LLVM

https://reviews.llvm.org/D32348

Files:
  clang/test/Index/print-type.cpp
  clang/tools/libclang/CXType.cpp


Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -147,9 +147,6 @@
 static Optional>
 GetTemplateArguments(QualType Type) {
   assert(!Type.isNull());
-  if (const auto *Specialization = Type->getAs())
-return Specialization->template_arguments();
-
   if (const auto *RecordDecl = Type->getAsCXXRecordDecl()) {
 const auto *TemplateDecl =
   dyn_cast(RecordDecl);
@@ -157,6 +154,9 @@
   return TemplateDecl->getTemplateArgs().asArray();
   }
 
+  if (const auto *Specialization = Type->getAs())
+return Specialization->template_arguments();
+
   return None;
 }
 
Index: clang/test/Index/print-type.cpp
===
--- clang/test/Index/print-type.cpp
+++ clang/test/Index/print-type.cpp
@@ -71,6 +71,11 @@
 Specialization& > templRefParam;
 auto autoTemplRefParam = templRefParam;
 
+template
+struct DefaultedTypeExample {};
+
+typedef DefaultedTypeExample DefaultedTypeAlias;
+
 // 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]
@@ -115,7 +120,7 @@
 // CHECK: TemplateRef=Baz:9:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
 // CHECK: TemplateRef=Foo:4:8 [type=] [typekind=Invalid] [isPOD=0]
-// CHECK: FieldDecl=qux:29:38 (Definition) [type=Qux, 
outer::inner::Bar::FooType>] [typekind=Unexposed] [templateargs/4= [type=int] 
[typekind=Int] [type=char *] [typekind=Pointer] [type=Foo] 
[typekind=Unexposed] [type=outer::inner::Bar::FooType] [typekind=Typedef]] 
[canonicaltype=outer::Qux, int>] 
[canonicaltypekind=Record] [canonicaltemplateargs/4= [type=int] [typekind=Int] 
[type=char *] [typekind=Pointer] [type=outer::Foo] [typekind=Record] 
[type=int] [typekind=Int]] [isPOD=1]
+// CHECK: FieldDecl=qux:29:38 (Definition) [type=Qux, 
outer::inner::Bar::FooType>] [typekind=Unexposed] [templateargs/4= [type=int] 
[typekind=Int] [type=char *] [typekind=Pointer] [type=outer::Foo] 
[typekind=Record] [type=int] [typekind=Int]] [canonicaltype=outer::Qux, int>] [canonicaltypekind=Record] 
[canonicaltemplateargs/4= [type=int] [typekind=Int] [type=char *] 
[typekind=Pointer] [type=outer::Foo] [typekind=Record] [type=int] 
[typekind=Int]] [isPOD=1]
 // CHECK: TemplateRef=Qux:12:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: TemplateRef=Foo:4:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: FunctionTemplate=tbar:36:3 [type=T (int)] [typekind=FunctionProto] 
[canonicaltype=type-parameter-0-0 (int)] [canonicaltypekind=FunctionProto] 
[resulttype=T] [resulttypekind=Unexposed] [isPOD=0]
@@ -177,3 +182,4 @@
 // CHECK: VarDecl=autoTemplRefParam:72:6 (Definition) 
[type=Specialization &>] [typekind=Auto] [templateargs/1= 
[type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=Specialization &>] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: UnexposedExpr=templRefParam:71:40 [type=const 
Specialization &>] [typekind=Unexposed] const 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=const Specialization &>] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: DeclRefExpr=templRefParam:71:40 
[type=Specialization &>] [typekind=Unexposed] 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=Specialization &>] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
+// CHECK: TypedefDecl=DefaultedTypeAlias:77:35 (Definition) 
[type=DefaultedTypeAlias] [typekind=Typedef] [templateargs/2= [type=int] 
[typekind=Int] [type=int] [typekind=Int]] 
[canonicaltype=DefaultedTypeExample] [canonicaltypekind=Record] 
[canonicaltemplateargs/2= [type=int] [typekind=Int] [type=int] [typekind=Int]] 
[isPOD=0]


Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -147,9 +147,6 @@
 static Optional>
 GetTemplateArguments(QualType Type) {
   assert(!Type.isNull());
-  if (const auto *Specialization = Type->getAs())
-  

[PATCH] D32348: [libclang] Check for a record declaration before a template specialization.

2017-04-21 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio updated this revision to Diff 96130.
emilio added a comment.

Full diff, thanks @arphaman :)


https://reviews.llvm.org/D32348

Files:
  clang/test/Index/print-type.cpp
  clang/tools/libclang/CXType.cpp


Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -147,16 +147,16 @@
 static Optional>
 GetTemplateArguments(QualType Type) {
   assert(!Type.isNull());
-  if (const auto *Specialization = Type->getAs())
-return Specialization->template_arguments();
-
   if (const auto *RecordDecl = Type->getAsCXXRecordDecl()) {
 const auto *TemplateDecl =
   dyn_cast(RecordDecl);
 if (TemplateDecl)
   return TemplateDecl->getTemplateArgs().asArray();
   }
 
+  if (const auto *Specialization = Type->getAs())
+return Specialization->template_arguments();
+
   return None;
 }
 
Index: clang/test/Index/print-type.cpp
===
--- clang/test/Index/print-type.cpp
+++ clang/test/Index/print-type.cpp
@@ -71,6 +71,11 @@
 Specialization& > templRefParam;
 auto autoTemplRefParam = templRefParam;
 
+template
+struct DefaultedTypeExample {};
+
+typedef DefaultedTypeExample DefaultedTypeAlias;
+
 // 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]
@@ -115,7 +120,7 @@
 // CHECK: TemplateRef=Baz:9:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
 // CHECK: TemplateRef=Foo:4:8 [type=] [typekind=Invalid] [isPOD=0]
-// CHECK: FieldDecl=qux:29:38 (Definition) [type=Qux, 
outer::inner::Bar::FooType>] [typekind=Unexposed] [templateargs/4= [type=int] 
[typekind=Int] [type=char *] [typekind=Pointer] [type=Foo] 
[typekind=Unexposed] [type=outer::inner::Bar::FooType] [typekind=Typedef]] 
[canonicaltype=outer::Qux, int>] 
[canonicaltypekind=Record] [canonicaltemplateargs/4= [type=int] [typekind=Int] 
[type=char *] [typekind=Pointer] [type=outer::Foo] [typekind=Record] 
[type=int] [typekind=Int]] [isPOD=1]
+// CHECK: FieldDecl=qux:29:38 (Definition) [type=Qux, 
outer::inner::Bar::FooType>] [typekind=Unexposed] [templateargs/4= [type=int] 
[typekind=Int] [type=char *] [typekind=Pointer] [type=outer::Foo] 
[typekind=Record] [type=int] [typekind=Int]] [canonicaltype=outer::Qux, int>] [canonicaltypekind=Record] 
[canonicaltemplateargs/4= [type=int] [typekind=Int] [type=char *] 
[typekind=Pointer] [type=outer::Foo] [typekind=Record] [type=int] 
[typekind=Int]] [isPOD=1]
 // CHECK: TemplateRef=Qux:12:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: TemplateRef=Foo:4:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: FunctionTemplate=tbar:36:3 [type=T (int)] [typekind=FunctionProto] 
[canonicaltype=type-parameter-0-0 (int)] [canonicaltypekind=FunctionProto] 
[resulttype=T] [resulttypekind=Unexposed] [isPOD=0]
@@ -177,3 +182,4 @@
 // CHECK: VarDecl=autoTemplRefParam:72:6 (Definition) 
[type=Specialization &>] [typekind=Auto] [templateargs/1= 
[type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=Specialization &>] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: UnexposedExpr=templRefParam:71:40 [type=const 
Specialization &>] [typekind=Unexposed] const 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=const Specialization &>] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: DeclRefExpr=templRefParam:71:40 
[type=Specialization &>] [typekind=Unexposed] 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=Specialization &>] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
+// CHECK: TypedefDecl=DefaultedTypeAlias:77:35 (Definition) 
[type=DefaultedTypeAlias] [typekind=Typedef] [templateargs/2= [type=int] 
[typekind=Int] [type=int] [typekind=Int]] 
[canonicaltype=DefaultedTypeExample] [canonicaltypekind=Record] 
[canonicaltemplateargs/2= [type=int] [typekind=Int] [type=int] [typekind=Int]] 
[isPOD=0]


Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -147,16 +147,16 @@
 static Optional>
 GetTemplateArguments(QualType Type) {
   assert(!Type.isNull());
-  if (const auto *Specialization = Type->getAs())
-return Specialization->template_arguments();
-
   if (const auto *RecordDecl = Type->getAsCXXRecordDecl()) {
 const auto *TemplateDecl =
   dyn_cast(RecordDecl);
 if (TemplateDecl)
   return TemplateDecl->getTemplateArgs().asArray();
   }
 
+  if (const auto 

[PATCH] D32348: [libclang] Check for a record declaration before a template specialization.

2017-04-21 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added inline comments.



Comment at: clang/test/Index/print-type.cpp:118
 // CHECK: TemplateRef=Foo:4:8 [type=] [typekind=Invalid] [isPOD=0]
-// CHECK: FieldDecl=qux:29:38 (Definition) [type=Qux, 
outer::inner::Bar::FooType>] [typekind=Unexposed] [templateargs/4= [type=int] 
[typekind=Int] [type=char *] [typekind=Pointer] [type=Foo] 
[typekind=Unexposed] [type=outer::inner::Bar::FooType] [typekind=Typedef]] 
[canonicaltype=outer::Qux, int>] 
[canonicaltypekind=Record] [canonicaltemplateargs/4= [type=int] [typekind=Int] 
[type=char *] [typekind=Pointer] [type=outer::Foo] [typekind=Record] 
[type=int] [typekind=Int]] [isPOD=1]
 // CHECK: TemplateRef=Qux:12:8 [type=] [typekind=Invalid] [isPOD=0]

arphaman wrote:
> Hmm, that's an interesting change. I assume the test passed prior to this 
> patch, right? Did this output change purely because of the change in 
> `GetTemplateArguments`?
Yup, that's right. This makes the type and the canonical type match in this 
case. In this case we lose a tiny bit of information (mainly, that the template 
argument was used through a typedef), but the alternative is to lose 
information about default template parameters, which seems worse to me (and is 
a regression, while template argument packs haven't been inspectionable until 
libclang 4.0).


https://reviews.llvm.org/D32348



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32389: [libclang] Expose some target information via the C API.

2017-04-22 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio created this revision.
emilio added a project: clang-c.

This allows users to query the target triple and target pointer width, which
would make me able to fix https://github.com/servo/rust-bindgen/issues/593 and
other related bugs in an elegant way (without having to manually parse the
target triple in the command line arguments).


Repository:
  rL LLVM

https://reviews.llvm.org/D32389

Files:
  clang/include/clang-c/Index.h
  clang/test/Index/target-info.c
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/libclang.exports

Index: clang/tools/libclang/libclang.exports
===
--- clang/tools/libclang/libclang.exports
+++ clang/tools/libclang/libclang.exports
@@ -250,6 +250,8 @@
 clang_getTokenSpelling
 clang_getTranslationUnitCursor
 clang_getTranslationUnitSpelling
+clang_getTranslationUnitTargetTriple
+clang_getTranslationUnitTargetPointerWidth
 clang_getTypeDeclaration
 clang_getTypeKindSpelling
 clang_getTypeSpelling
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -26,6 +26,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticCategories.h"
 #include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/Version.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -4005,6 +4006,28 @@
   return cxstring::createDup(CXXUnit->getOriginalSourceFileName());
 }
 
+CXString clang_getTranslationUnitTargetTriple(CXTranslationUnit CTUnit) {
+  if (isNotUsableTU(CTUnit)) {
+LOG_BAD_TU(CTUnit);
+return cxstring::createEmpty();
+  }
+
+  ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
+  std::string Triple =
+CXXUnit->getASTContext().getTargetInfo().getTriple().normalize();
+  return cxstring::createDup(Triple);
+}
+
+int clang_getTranslationUnitTargetPointerWidth(CXTranslationUnit CTUnit) {
+  if (isNotUsableTU(CTUnit)) {
+LOG_BAD_TU(CTUnit);
+return -1;
+  }
+
+  ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
+  return CXXUnit->getASTContext().getTargetInfo().getMaxPointerWidth();
+}
+
 CXCursor clang_getTranslationUnitCursor(CXTranslationUnit TU) {
   if (isNotUsableTU(TU)) {
 LOG_BAD_TU(TU);
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -1560,6 +1560,47 @@
 }
 
 /**/
+/* Target information testing.*/
+/**/
+
+static int print_target_info(int argc, const char **argv) {
+  CXIndex Idx;
+  CXTranslationUnit TU;
+  const char *FileName;
+  enum CXErrorCode Err;
+  CXString Target;
+  int PointerWidth;
+
+  if (argc == 0) {
+fprintf(stderr, "No filename specified\n");
+return 1;
+  }
+
+  FileName = argv[1];
+
+  Idx = clang_createIndex(0, 1);
+  Err = clang_parseTranslationUnit2(Idx, FileName, argv, argc, NULL, 0,
+getDefaultParsingOptions(), &TU);
+  if (Err != CXError_Success) {
+fprintf(stderr, "Couldn't parse translation unit!\n");
+describeLibclangFailure(Err);
+clang_disposeIndex(Idx);
+return 1;
+  }
+
+  Target = clang_getTranslationUnitTargetTriple(TU);
+  printf("TargetTriple: %s\n", clang_getCString(Target));
+  clang_disposeString(Target);
+
+  PointerWidth = clang_getTranslationUnitTargetPointerWidth(TU);
+  printf("PointerWidth: %d\n", PointerWidth);
+
+  clang_disposeTranslationUnit(TU);
+  clang_disposeIndex(Idx);
+  return 0;
+}
+
+/**/
 /* Loading ASTs/source.   */
 /**/
 
@@ -4297,11 +4338,12 @@
 "   c-index-test -test-print-type {}*\n"
 "   c-index-test -test-print-type-size {}*\n"
 "   c-index-test -test-print-bitwidth {}*\n"
+"   c-index-test -test-print-target-info {}*\n"
 "   c-index-test -test-print-type-declaration {}*\n"
 "   c-index-test -print-usr [ {}]*\n"
-"   c-index-test -print-usr-file \n"
-"   c-index-test -write-pch  \n");
+"   c-index-test -print-usr-file \n");
   fprintf(stderr,
+"   c-index-test -write-pch  \n"
 "   c-index-test -compilation-db [lookup ] database\n");
   fprintf(stderr,
 "   c-index-test -print-build-session-timestamp\n");
@@ -4407,6 +4449,8 @@
 return perform_test_load_tu(argv[2], "all", NULL, PrintMangledName, NULL);
   else if (argc > 2 && strcmp(argv[1], "-test-print-manglings") == 0)
 r

[PATCH] D32389: [libclang] Expose some target information via the C API.

2017-04-22 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a comment.

I'd appreciate if anyone could point me to an appropriate reviewer for this.

Thanks in advance! :)


Repository:
  rL LLVM

https://reviews.llvm.org/D32389



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32348: [libclang] Check for a record declaration before a template specialization.

2017-04-25 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a comment.

Yes, please! I've submitted a few patches, but still no commit access.

Thanks!


https://reviews.llvm.org/D32348



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32389: [libclang] Expose some target information via the C API.

2017-04-25 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a comment.

Sounds good to me, will do :)


Repository:
  rL LLVM

https://reviews.llvm.org/D32389



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32389: [libclang] Expose some target information via the C API.

2017-04-25 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio updated this revision to Diff 96652.
emilio added a comment.

Updated per comments, I used `clang_TargetInfo_dispose` following recent APIs 
instead of `clang_disposeTargetInfo`, let me know if I should change that.

Also, didn't add a new header for `CXTargetInfo`, since it's rather small, but 
can definitely do if needed.


Repository:
  rL LLVM

https://reviews.llvm.org/D32389

Files:
  clang/include/clang-c/Index.h
  clang/test/Index/target-info.c
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXTranslationUnit.h
  clang/tools/libclang/libclang.exports

Index: clang/tools/libclang/libclang.exports
===
--- clang/tools/libclang/libclang.exports
+++ clang/tools/libclang/libclang.exports
@@ -79,6 +79,9 @@
 clang_TParamCommandComment_isParamPositionValid
 clang_TParamCommandComment_getDepth
 clang_TParamCommandComment_getIndex
+clang_TargetInfo_dispose
+clang_TargetInfo_getPointerWidth
+clang_TargetInfo_getTriple
 clang_Type_getAlignOf
 clang_Type_getClassType
 clang_Type_getSizeOf
@@ -250,6 +253,7 @@
 clang_getTokenSpelling
 clang_getTranslationUnitCursor
 clang_getTranslationUnitSpelling
+clang_getTranslationUnitTargetInfo
 clang_getTypeDeclaration
 clang_getTypeKindSpelling
 clang_getTypeSpelling
Index: clang/tools/libclang/CXTranslationUnit.h
===
--- clang/tools/libclang/CXTranslationUnit.h
+++ clang/tools/libclang/CXTranslationUnit.h
@@ -35,6 +35,10 @@
   clang::index::CommentToXMLConverter *CommentToXML;
 };
 
+struct CXTargetInfoImpl {
+  CXTranslationUnit TranslationUnit;
+};
+
 namespace clang {
 namespace cxtu {
 
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -26,6 +26,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticCategories.h"
 #include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/Version.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -4015,6 +4016,48 @@
   return MakeCXCursor(CXXUnit->getASTContext().getTranslationUnitDecl(), TU);
 }
 
+CXTargetInfo clang_getTranslationUnitTargetInfo(CXTranslationUnit CTUnit) {
+  if (isNotUsableTU(CTUnit)) {
+LOG_BAD_TU(CTUnit);
+return nullptr;
+  }
+
+  CXTargetInfoImpl* impl = new CXTargetInfoImpl();
+  impl->TranslationUnit = CTUnit;
+  return impl;
+}
+
+CXString clang_TargetInfo_getTriple(CXTargetInfo TargetInfo) {
+  if (!TargetInfo)
+return cxstring::createEmpty();
+
+  CXTranslationUnit CTUnit = TargetInfo->TranslationUnit;
+  assert(!isNotUsableTU(CTUnit));
+
+  ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
+  std::string Triple =
+CXXUnit->getASTContext().getTargetInfo().getTriple().normalize();
+  return cxstring::createDup(Triple);
+}
+
+int clang_TargetInfo_getPointerWidth(CXTargetInfo TargetInfo) {
+  if (!TargetInfo)
+return -1;
+
+  CXTranslationUnit CTUnit = TargetInfo->TranslationUnit;
+  assert(!isNotUsableTU(CTUnit));
+
+  ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
+  return CXXUnit->getASTContext().getTargetInfo().getMaxPointerWidth();
+}
+
+void clang_TargetInfo_dispose(CXTargetInfo TargetInfo) {
+  if (!TargetInfo)
+return;
+
+  delete TargetInfo;
+}
+
 //===--===//
 // CXFile Operations.
 //===--===//
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -1560,6 +1560,51 @@
 }
 
 /**/
+/* Target information testing.*/
+/**/
+
+static int print_target_info(int argc, const char **argv) {
+  CXIndex Idx;
+  CXTranslationUnit TU;
+  CXTargetInfo TargetInfo;
+  CXString Triple;
+  const char *FileName;
+  enum CXErrorCode Err;
+  int PointerWidth;
+
+  if (argc == 0) {
+fprintf(stderr, "No filename specified\n");
+return 1;
+  }
+
+  FileName = argv[1];
+
+  Idx = clang_createIndex(0, 1);
+  Err = clang_parseTranslationUnit2(Idx, FileName, argv, argc, NULL, 0,
+getDefaultParsingOptions(), &TU);
+  if (Err != CXError_Success) {
+fprintf(stderr, "Couldn't parse translation unit!\n");
+describeLibclangFailure(Err);
+clang_disposeIndex(Idx);
+return 1;
+  }
+
+  TargetInfo = clang_getTranslationUnitTargetInfo(TU);
+
+  Triple = clang_TargetInfo_getTriple(TargetInfo);
+  printf("TargetTriple: %s\n", clang_getCString(Triple));
+  clang_disposeString(Tripl

[PATCH] D32348: [libclang] Check for a record declaration before a template specialization.

2017-04-26 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a comment.

In https://reviews.llvm.org/D32348#738704, @rsmith wrote:

> This change looks like it introduces a regression itself: given
>
>   template struct A {};
>   template using B = A;
>   B bi;
>
>
> ... requesting the template arguments for the type `B` changes from 
> producing  `int` to producing `int*` with this patch, which seems to directly 
> oppose the intentions of https://reviews.llvm.org/D26663.


FWIW when I wrote https://reviews.llvm.org/D26663, I did it because arguments 
weren't inspectionable at all for `using` declarations. Actually both of them 
would've worked for me.

>   template using C = T;
> 
> 
> With this patch, requesting the template arguments for `C` gives `int` 
> but requesting the template arguments of `C>` gives `void` rather 
> than `A`.

That being said, that is _specially_ annoying (good catch btw). Annoying enough 
to justify reverting this change I'd say...

I'll submit something with the test-cases. I guess people that depended on the 
old translation will just need to live with it... shrug.

I guess I could do something clever like: If it's both a 
`ClassTemplateSpecializationDecl`, and a `TemplateSpecializationType`, and the 
template arguments of the second happen to not be a template specialization, 
then use the `ClassTemplateSpecializationDecl`, otherwise the other, but that 
seems fairly tricky to maintain, so I'd rather just do the former.

Thanks for looking through it, btw.


Repository:
  rL LLVM

https://reviews.llvm.org/D32348



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32389: [libclang] Expose some target information via the C API.

2017-04-26 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio updated this revision to Diff 96834.
emilio added a comment.

Updated per review comments, thanks :)


Repository:
  rL LLVM

https://reviews.llvm.org/D32389

Files:
  clang/include/clang-c/Index.h
  clang/test/Index/target-info.c
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXTranslationUnit.h
  clang/tools/libclang/libclang.exports

Index: clang/tools/libclang/libclang.exports
===
--- clang/tools/libclang/libclang.exports
+++ clang/tools/libclang/libclang.exports
@@ -79,6 +79,9 @@
 clang_TParamCommandComment_isParamPositionValid
 clang_TParamCommandComment_getDepth
 clang_TParamCommandComment_getIndex
+clang_TargetInfo_dispose
+clang_TargetInfo_getPointerWidth
+clang_TargetInfo_getTriple
 clang_Type_getAlignOf
 clang_Type_getClassType
 clang_Type_getSizeOf
@@ -250,6 +253,7 @@
 clang_getTokenSpelling
 clang_getTranslationUnitCursor
 clang_getTranslationUnitSpelling
+clang_getTranslationUnitTargetInfo
 clang_getTypeDeclaration
 clang_getTypeKindSpelling
 clang_getTypeSpelling
Index: clang/tools/libclang/CXTranslationUnit.h
===
--- clang/tools/libclang/CXTranslationUnit.h
+++ clang/tools/libclang/CXTranslationUnit.h
@@ -35,6 +35,10 @@
   clang::index::CommentToXMLConverter *CommentToXML;
 };
 
+struct CXTargetInfoImpl {
+  CXTranslationUnit TranslationUnit;
+};
+
 namespace clang {
 namespace cxtu {
 
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -26,6 +26,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticCategories.h"
 #include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/Version.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -4015,6 +4016,50 @@
   return MakeCXCursor(CXXUnit->getASTContext().getTranslationUnitDecl(), TU);
 }
 
+CXTargetInfo clang_getTranslationUnitTargetInfo(CXTranslationUnit CTUnit) {
+  if (isNotUsableTU(CTUnit)) {
+LOG_BAD_TU(CTUnit);
+return nullptr;
+  }
+
+  CXTargetInfoImpl* impl = new CXTargetInfoImpl();
+  impl->TranslationUnit = CTUnit;
+  return impl;
+}
+
+CXString clang_TargetInfo_getTriple(CXTargetInfo TargetInfo) {
+  if (!TargetInfo)
+return cxstring::createEmpty();
+
+  CXTranslationUnit CTUnit = TargetInfo->TranslationUnit;
+  assert(!isNotUsableTU(CTUnit) &&
+ "Unexpected unusable translation unit in TargetInfo");
+
+  ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
+  std::string Triple =
+CXXUnit->getASTContext().getTargetInfo().getTriple().normalize();
+  return cxstring::createDup(Triple);
+}
+
+int clang_TargetInfo_getPointerWidth(CXTargetInfo TargetInfo) {
+  if (!TargetInfo)
+return -1;
+
+  CXTranslationUnit CTUnit = TargetInfo->TranslationUnit;
+  assert(!isNotUsableTU(CTUnit) &&
+ "Unexpected unusable translation unit in TargetInfo");
+
+  ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
+  return CXXUnit->getASTContext().getTargetInfo().getMaxPointerWidth();
+}
+
+void clang_TargetInfo_dispose(CXTargetInfo TargetInfo) {
+  if (!TargetInfo)
+return;
+
+  delete TargetInfo;
+}
+
 //===--===//
 // CXFile Operations.
 //===--===//
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -1560,6 +1560,51 @@
 }
 
 /**/
+/* Target information testing.*/
+/**/
+
+static int print_target_info(int argc, const char **argv) {
+  CXIndex Idx;
+  CXTranslationUnit TU;
+  CXTargetInfo TargetInfo;
+  CXString Triple;
+  const char *FileName;
+  enum CXErrorCode Err;
+  int PointerWidth;
+
+  if (argc == 0) {
+fprintf(stderr, "No filename specified\n");
+return 1;
+  }
+
+  FileName = argv[1];
+
+  Idx = clang_createIndex(0, 1);
+  Err = clang_parseTranslationUnit2(Idx, FileName, argv, argc, NULL, 0,
+getDefaultParsingOptions(), &TU);
+  if (Err != CXError_Success) {
+fprintf(stderr, "Couldn't parse translation unit!\n");
+describeLibclangFailure(Err);
+clang_disposeIndex(Idx);
+return 1;
+  }
+
+  TargetInfo = clang_getTranslationUnitTargetInfo(TU);
+
+  Triple = clang_TargetInfo_getTriple(TargetInfo);
+  printf("TargetTriple: %s\n", clang_getCString(Triple));
+  clang_disposeString(Triple);
+
+  PointerWidth = clang_TargetInfo_getPointerWidth(TargetInfo);
+  printf("PointerWidth

[PATCH] D32566: Revert rL301328 and add tests for the regressions introduced.

2017-04-26 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio created this revision.
emilio added a project: clang-c.

See https://reviews.llvm.org/D32348#738704


Repository:
  rL LLVM

https://reviews.llvm.org/D32566

Files:
  clang/test/Index/print-type.cpp
  clang/tools/libclang/CXType.cpp


Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -147,16 +147,16 @@
 static Optional>
 GetTemplateArguments(QualType Type) {
   assert(!Type.isNull());
+  if (const auto *Specialization = Type->getAs())
+return Specialization->template_arguments();
+
   if (const auto *RecordDecl = Type->getAsCXXRecordDecl()) {
 const auto *TemplateDecl =
   dyn_cast(RecordDecl);
 if (TemplateDecl)
   return TemplateDecl->getTemplateArgs().asArray();
   }
 
-  if (const auto *Specialization = Type->getAs())
-return Specialization->template_arguments();
-
   return None;
 }
 
Index: clang/test/Index/print-type.cpp
===
--- clang/test/Index/print-type.cpp
+++ clang/test/Index/print-type.cpp
@@ -71,10 +71,9 @@
 Specialization& > templRefParam;
 auto autoTemplRefParam = templRefParam;
 
-template
-struct DefaultedTypeExample {};
-
-typedef DefaultedTypeExample DefaultedTypeAlias;
+template struct A {};
+template using C = T;
+using baz = C>;
 
 // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
@@ -120,7 +119,7 @@
 // CHECK: TemplateRef=Baz:9:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
 // CHECK: TemplateRef=Foo:4:8 [type=] [typekind=Invalid] [isPOD=0]
-// CHECK: FieldDecl=qux:29:38 (Definition) [type=Qux, 
outer::inner::Bar::FooType>] [typekind=Unexposed] [templateargs/4= [type=int] 
[typekind=Int] [type=char *] [typekind=Pointer] [type=outer::Foo] 
[typekind=Record] [type=int] [typekind=Int]] [canonicaltype=outer::Qux, int>] [canonicaltypekind=Record] 
[canonicaltemplateargs/4= [type=int] [typekind=Int] [type=char *] 
[typekind=Pointer] [type=outer::Foo] [typekind=Record] [type=int] 
[typekind=Int]] [isPOD=1]
+// CHECK: FieldDecl=qux:29:38 (Definition) [type=Qux, 
outer::inner::Bar::FooType>] [typekind=Unexposed] [templateargs/4= [type=int] 
[typekind=Int] [type=char *] [typekind=Pointer] [type=Foo] 
[typekind=Unexposed] [type=outer::inner::Bar::FooType] [typekind=Typedef]] 
[canonicaltype=outer::Qux, int>] 
[canonicaltypekind=Record] [canonicaltemplateargs/4= [type=int] [typekind=Int] 
[type=char *] [typekind=Pointer] [type=outer::Foo] [typekind=Record] 
[type=int] [typekind=Int]] [isPOD=1]
 // CHECK: TemplateRef=Qux:12:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: TemplateRef=Foo:4:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: FunctionTemplate=tbar:36:3 [type=T (int)] [typekind=FunctionProto] 
[canonicaltype=type-parameter-0-0 (int)] [canonicaltypekind=FunctionProto] 
[resulttype=T] [resulttypekind=Unexposed] [isPOD=0]
@@ -182,4 +181,4 @@
 // CHECK: VarDecl=autoTemplRefParam:72:6 (Definition) 
[type=Specialization &>] [typekind=Auto] [templateargs/1= 
[type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=Specialization &>] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: UnexposedExpr=templRefParam:71:40 [type=const 
Specialization &>] [typekind=Unexposed] const 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=const Specialization &>] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: DeclRefExpr=templRefParam:71:40 
[type=Specialization &>] [typekind=Unexposed] 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=Specialization &>] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
-// CHECK: TypedefDecl=DefaultedTypeAlias:77:35 (Definition) 
[type=DefaultedTypeAlias] [typekind=Typedef] [templateargs/2= [type=int] 
[typekind=Int] [type=int] [typekind=Int]] 
[canonicaltype=DefaultedTypeExample] [canonicaltypekind=Record] 
[canonicaltemplateargs/2= [type=int] [typekind=Int] [type=int] [typekind=Int]] 
[isPOD=0]
+// CHECK: TypeAliasDecl=baz:76:7 (Definition) [type=baz] [typekind=Typedef] 
[templateargs/1= [type=A] [typekind=Unexposed]] [canonicaltype=A] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=void] 
[typekind=Void]] [isPOD=0]


Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -147,16 +147,16 @@
 static Optional>
 GetTemplateArguments(QualType Type) {
   assert(!Type.isNull());
+  if (const auto *Specialization = Type->getAs())
+return Specialization->templ

[PATCH] D32348: [libclang] Check for a record declaration before a template specialization.

2017-04-26 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a comment.

Revert + tests @ https://reviews.llvm.org/D32566


Repository:
  rL LLVM

https://reviews.llvm.org/D32348



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32348: [libclang] Check for a record declaration before a template specialization.

2017-04-26 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a comment.

> FWIW when I wrote https://reviews.llvm.org/D26663, I did it because arguments 
> weren't inspectionable at all for `using` declarations. Actually both of them 
> would've worked for me.

Also, this bit was not completely accurate, and you could inspect ones, but not 
others (you could inspect the ones that desugared into a RecordDecl that 
happened to be a template specialization, as shown by the bug you pointed out).


Repository:
  rL LLVM

https://reviews.llvm.org/D32348



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32566: Revert rL301328 and add tests for the regressions introduced.

2017-04-27 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a comment.

I'm personally fine with this behavior in particular, given you can check the 
cursor you're querying to know if it's a typedef or alias specialization. Of 
course I'm not the only one using libclang, though, so I'd be interested in 
hearing other people's opinion.

I think that  we should try to prevent this _third_ different behavior to stay 
in tree in the meantime, though, what do you think?


Repository:
  rL LLVM

https://reviews.llvm.org/D32566



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32389: [libclang] Expose some target information via the C API.

2017-04-28 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL301648: [libclang] Expose some target information via the C 
API. (authored by emilio).

Changed prior to commit:
  https://reviews.llvm.org/D32389?vs=96834&id=97109#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32389

Files:
  cfe/trunk/include/clang-c/Index.h
  cfe/trunk/test/Index/target-info.c
  cfe/trunk/tools/c-index-test/c-index-test.c
  cfe/trunk/tools/libclang/CIndex.cpp
  cfe/trunk/tools/libclang/CXTranslationUnit.h
  cfe/trunk/tools/libclang/libclang.exports

Index: cfe/trunk/tools/libclang/CIndex.cpp
===
--- cfe/trunk/tools/libclang/CIndex.cpp
+++ cfe/trunk/tools/libclang/CIndex.cpp
@@ -26,6 +26,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticCategories.h"
 #include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/Version.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -4018,6 +4019,50 @@
   return MakeCXCursor(CXXUnit->getASTContext().getTranslationUnitDecl(), TU);
 }
 
+CXTargetInfo clang_getTranslationUnitTargetInfo(CXTranslationUnit CTUnit) {
+  if (isNotUsableTU(CTUnit)) {
+LOG_BAD_TU(CTUnit);
+return nullptr;
+  }
+
+  CXTargetInfoImpl* impl = new CXTargetInfoImpl();
+  impl->TranslationUnit = CTUnit;
+  return impl;
+}
+
+CXString clang_TargetInfo_getTriple(CXTargetInfo TargetInfo) {
+  if (!TargetInfo)
+return cxstring::createEmpty();
+
+  CXTranslationUnit CTUnit = TargetInfo->TranslationUnit;
+  assert(!isNotUsableTU(CTUnit) &&
+ "Unexpected unusable translation unit in TargetInfo");
+
+  ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
+  std::string Triple =
+CXXUnit->getASTContext().getTargetInfo().getTriple().normalize();
+  return cxstring::createDup(Triple);
+}
+
+int clang_TargetInfo_getPointerWidth(CXTargetInfo TargetInfo) {
+  if (!TargetInfo)
+return -1;
+
+  CXTranslationUnit CTUnit = TargetInfo->TranslationUnit;
+  assert(!isNotUsableTU(CTUnit) &&
+ "Unexpected unusable translation unit in TargetInfo");
+
+  ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
+  return CXXUnit->getASTContext().getTargetInfo().getMaxPointerWidth();
+}
+
+void clang_TargetInfo_dispose(CXTargetInfo TargetInfo) {
+  if (!TargetInfo)
+return;
+
+  delete TargetInfo;
+}
+
 //===--===//
 // CXFile Operations.
 //===--===//
Index: cfe/trunk/tools/libclang/CXTranslationUnit.h
===
--- cfe/trunk/tools/libclang/CXTranslationUnit.h
+++ cfe/trunk/tools/libclang/CXTranslationUnit.h
@@ -35,6 +35,10 @@
   clang::index::CommentToXMLConverter *CommentToXML;
 };
 
+struct CXTargetInfoImpl {
+  CXTranslationUnit TranslationUnit;
+};
+
 namespace clang {
 namespace cxtu {
 
Index: cfe/trunk/tools/libclang/libclang.exports
===
--- cfe/trunk/tools/libclang/libclang.exports
+++ cfe/trunk/tools/libclang/libclang.exports
@@ -79,6 +79,9 @@
 clang_TParamCommandComment_isParamPositionValid
 clang_TParamCommandComment_getDepth
 clang_TParamCommandComment_getIndex
+clang_TargetInfo_dispose
+clang_TargetInfo_getPointerWidth
+clang_TargetInfo_getTriple
 clang_Type_getAlignOf
 clang_Type_getClassType
 clang_Type_getSizeOf
@@ -250,6 +253,7 @@
 clang_getTokenSpelling
 clang_getTranslationUnitCursor
 clang_getTranslationUnitSpelling
+clang_getTranslationUnitTargetInfo
 clang_getTypeDeclaration
 clang_getTypeKindSpelling
 clang_getTypeSpelling
Index: cfe/trunk/tools/c-index-test/c-index-test.c
===
--- cfe/trunk/tools/c-index-test/c-index-test.c
+++ cfe/trunk/tools/c-index-test/c-index-test.c
@@ -1560,6 +1560,51 @@
 }
 
 /**/
+/* Target information testing.*/
+/**/
+
+static int print_target_info(int argc, const char **argv) {
+  CXIndex Idx;
+  CXTranslationUnit TU;
+  CXTargetInfo TargetInfo;
+  CXString Triple;
+  const char *FileName;
+  enum CXErrorCode Err;
+  int PointerWidth;
+
+  if (argc == 0) {
+fprintf(stderr, "No filename specified\n");
+return 1;
+  }
+
+  FileName = argv[1];
+
+  Idx = clang_createIndex(0, 1);
+  Err = clang_parseTranslationUnit2(Idx, FileName, argv, argc, NULL, 0,
+getDefaultParsingOptions(), &TU);
+  if (Err != CXError_Success) {
+fprintf(stderr, "Couldn't parse translation unit!\n");
+describeLibclangFailure(Err);
+clang_disposeIndex(Idx);
+return 1;
+  }
+
+  TargetInfo = clang_getTranslationUnitTargetInfo(TU);
+
+  Tri

[PATCH] D32566: Revert rL301328 and add tests for the regressions introduced.

2017-05-02 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL301902: [libclang] Revert rL301328 and add tests for the 
regressions introduced. (authored by emilio).

Changed prior to commit:
  https://reviews.llvm.org/D32566?vs=96838&id=97407#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32566

Files:
  cfe/trunk/test/Index/print-type.cpp
  cfe/trunk/tools/libclang/CXType.cpp


Index: cfe/trunk/tools/libclang/CXType.cpp
===
--- cfe/trunk/tools/libclang/CXType.cpp
+++ cfe/trunk/tools/libclang/CXType.cpp
@@ -147,16 +147,16 @@
 static Optional>
 GetTemplateArguments(QualType Type) {
   assert(!Type.isNull());
+  if (const auto *Specialization = Type->getAs())
+return Specialization->template_arguments();
+
   if (const auto *RecordDecl = Type->getAsCXXRecordDecl()) {
 const auto *TemplateDecl =
   dyn_cast(RecordDecl);
 if (TemplateDecl)
   return TemplateDecl->getTemplateArgs().asArray();
   }
 
-  if (const auto *Specialization = Type->getAs())
-return Specialization->template_arguments();
-
   return None;
 }
 
Index: cfe/trunk/test/Index/print-type.cpp
===
--- cfe/trunk/test/Index/print-type.cpp
+++ cfe/trunk/test/Index/print-type.cpp
@@ -71,10 +71,9 @@
 Specialization& > templRefParam;
 auto autoTemplRefParam = templRefParam;
 
-template
-struct DefaultedTypeExample {};
-
-typedef DefaultedTypeExample DefaultedTypeAlias;
+template struct A {};
+template using C = T;
+using baz = C>;
 
 // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
@@ -120,7 +119,7 @@
 // CHECK: TemplateRef=Baz:9:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
 // CHECK: TemplateRef=Foo:4:8 [type=] [typekind=Invalid] [isPOD=0]
-// CHECK: FieldDecl=qux:29:38 (Definition) [type=Qux, 
outer::inner::Bar::FooType>] [typekind=Unexposed] [templateargs/4= [type=int] 
[typekind=Int] [type=char *] [typekind=Pointer] [type=outer::Foo] 
[typekind=Record] [type=int] [typekind=Int]] [canonicaltype=outer::Qux, int>] [canonicaltypekind=Record] 
[canonicaltemplateargs/4= [type=int] [typekind=Int] [type=char *] 
[typekind=Pointer] [type=outer::Foo] [typekind=Record] [type=int] 
[typekind=Int]] [isPOD=1]
+// CHECK: FieldDecl=qux:29:38 (Definition) [type=Qux, 
outer::inner::Bar::FooType>] [typekind=Unexposed] [templateargs/4= [type=int] 
[typekind=Int] [type=char *] [typekind=Pointer] [type=Foo] 
[typekind=Unexposed] [type=outer::inner::Bar::FooType] [typekind=Typedef]] 
[canonicaltype=outer::Qux, int>] 
[canonicaltypekind=Record] [canonicaltemplateargs/4= [type=int] [typekind=Int] 
[type=char *] [typekind=Pointer] [type=outer::Foo] [typekind=Record] 
[type=int] [typekind=Int]] [isPOD=1]
 // CHECK: TemplateRef=Qux:12:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: TemplateRef=Foo:4:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: FunctionTemplate=tbar:36:3 [type=T (int)] [typekind=FunctionProto] 
[canonicaltype=type-parameter-0-0 (int)] [canonicaltypekind=FunctionProto] 
[resulttype=T] [resulttypekind=Unexposed] [isPOD=0]
@@ -183,3 +182,4 @@
 // CHECK: UnexposedExpr=templRefParam:71:40 [type=const 
Specialization &>] [typekind=Unexposed] const 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=const Specialization &>] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: DeclRefExpr=templRefParam:71:40 
[type=Specialization &>] [typekind=Unexposed] 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=Specialization &>] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: TypedefDecl=DefaultedTypeAlias:77:35 (Definition) 
[type=DefaultedTypeAlias] [typekind=Typedef] [templateargs/2= [type=int] 
[typekind=Int] [type=int] [typekind=Int]] 
[canonicaltype=DefaultedTypeExample] [canonicaltypekind=Record] 
[canonicaltemplateargs/2= [type=int] [typekind=Int] [type=int] [typekind=Int]] 
[isPOD=0]
+// CHECK: TypeAliasDecl=baz:76:7 (Definition) [type=baz] [typekind=Typedef] 
[templateargs/1= [type=A] [typekind=Unexposed]] [canonicaltype=A] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=void] 
[typekind=Void]] [isPOD=0]


Index: cfe/trunk/tools/libclang/CXType.cpp
===
--- cfe/trunk/tools/libclang/CXType.cpp
+++ cfe/trunk/tools/libclang/CXType.cpp
@@ -147,16 +147,16 @@
 static Optional>
 GetTemplateArguments(QualType Type) {
   assert(!Type.isNull());
+  if (const auto *Specialization = Type->getAs())
+return Specialization->template_arguments();
+
   if (const auto *RecordDecl = Type->getAsCXXRecordDecl()) {
 const auto *Templa

[PATCH] D32566: Revert rL301328 and add tests for the regressions introduced.

2017-05-02 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a comment.

I sent http://lists.llvm.org/pipermail/cfe-dev/2017-May/053703.html


Repository:
  rL LLVM

https://reviews.llvm.org/D32566



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits