[PATCH] D137818: Add support for querying SubstTemplateTypeParm types

2022-11-21 Thread Anders Langlands via Phabricator via cfe-commits
anderslanglands updated this revision to Diff 476935.
anderslanglands added a comment.

Move getReplacementType to LLVM_16 block


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137818

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/test/Index/print-type.cpp
  clang/tools/libclang/CXType.cpp
  clang/tools/libclang/libclang.map

Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -412,6 +412,7 @@
 clang_CXXMethod_isDeleted;
 clang_CXXMethod_isCopyAssignmentOperator;
 clang_CXXMethod_isMoveAssignmentOperator;
+clang_Type_getReplacementType;
 };
 
 # Example of how to add a new symbol version entry.  If you do add a new symbol
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -118,13 +118,13 @@
 TKCASE(Attributed);
 TKCASE(BTFTagAttributed);
 TKCASE(Atomic);
+TKCASE(SubstTemplateTypeParm);
 default:
   return CXType_Unexposed;
   }
 #undef TKCASE
 }
 
-
 CXType cxtype::MakeCXType(QualType T, CXTranslationUnit TU) {
   CXTypeKind TK = CXType_Invalid;
 
@@ -635,6 +635,7 @@
 TKIND(OCLQueue);
 TKIND(OCLReserveID);
 TKIND(Atomic);
+TKIND(SubstTemplateTypeParm);
   }
 #undef TKIND
   return cxstring::createRef(s);
@@ -1355,3 +1356,11 @@
   const auto *AT = T->castAs();
   return MakeCXType(AT->getValueType(), GetTU(CT));
 }
+
+CXType clang_Type_getReplacementType(CXType CT) {
+  QualType T = GetQualType(CT);
+
+  const auto *ST =
+  !T.isNull() ? T->getAs() : nullptr;
+  return MakeCXType(ST ? ST->getReplacementType() : QualType(), GetTU(CT));
+}
Index: clang/test/Index/print-type.cpp
===
--- clang/test/Index/print-type.cpp
+++ clang/test/Index/print-type.cpp
@@ -171,7 +171,7 @@
 // CHECK: VarDecl=autoI:54:6 (Definition) [type=int] [typekind=Auto] [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1]
 // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
 // CHECK: VarDecl=autoTbar:55:6 (Definition) [type=int] [typekind=Auto] [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1]
-// CHECK: CallExpr=tbar:36:3 [type=int] [typekind=Unexposed] [canonicaltype=int] [canonicaltypekind=Int] [args= [int] [Int]] [isPOD=1]
+// CHECK: CallExpr=tbar:36:3 [type=int] [typekind=SubstTemplateTypeParm] [canonicaltype=int] [canonicaltypekind=Int] [args= [int] [Int]] [isPOD=1]
 // CHECK: UnexposedExpr=tbar:36:3 [type=int (*)(int)] [typekind=Pointer] [canonicaltype=int (*)(int)] [canonicaltypekind=Pointer] [isPOD=1] [pointeetype=int (int)] [pointeekind=FunctionProto]
 // CHECK: DeclRefExpr=tbar:36:3 RefName=[55:17 - 55:21] RefName=[55:21 - 55:26] [type=int (int)] [typekind=FunctionProto] [canonicaltype=int (int)] [canonicaltypekind=FunctionProto] [isPOD=0]
 // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
Index: clang/include/clang-c/Index.h
===
--- clang/include/clang-c/Index.h
+++ clang/include/clang-c/Index.h
@@ -2789,7 +2789,9 @@
 
   CXType_ExtVector = 176,
   CXType_Atomic = 177,
-  CXType_BTFTagAttributed = 178
+  CXType_BTFTagAttributed = 178,
+  /* Represents a type that has been substituted for a template type parameter. */
+  CXType_SubstTemplateTypeParm = 179
 };
 
 /**
@@ -3447,6 +3449,13 @@
  */
 CINDEX_LINKAGE CXType clang_Type_getValueType(CXType CT);
 
+/**
+ * Gets the replacement type for a SubstTemplateTypeParm type.
+ *
+ * If any other type kind is passed in, an invalid type is returned.
+ */
+CINDEX_LINKAGE CXType clang_Type_getReplacementType(CXType CT);
+
 /**
  * Return the offset of the field represented by the Cursor.
  *
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -806,6 +806,10 @@
   ``clang_Cursor_getTemplateArgumentType``, ``clang_Cursor_getTemplateArgumentValue`` and 
   ``clang_Cursor_getTemplateArgumentUnsignedValue`` now work on struct, class,
   and partial template specialization cursors in addition to function cursors.
+- Added ``CXType_SubstTemplateTypeParm`` to ``CXTypeKind``, which identifies a type that 
+  is a replacement for a template type parameter (previously reported a ``CXType_Unexposed``).
+- Introduced the new function ``clang_Type_getReplacementType`` which gets the type replacing
+  the template type parameter when type kind is ``CXType_SubstTemplateTypeParm``.
 
 Static Analyzer
 ---
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137818: Add support for querying SubstTemplateTypeParm types

2022-11-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D137818#3939213 , @anderslanglands 
wrote:

> Arg just noticed an issue: clang_Type_getReplacementType should be in the 
> LLVM_16 block in libclang.map not in the LLVM_13 block. I've blown away my 
> local branch so don't know how to fix the patch. Shall I just make a new 
> patch once this is merged?

In Phabricator, you can click the "Download Raw Diff" link (right-hand side of 
the page, near-ish the top) to get the patch back; you should be able to use 
that to get your local branch back to the same state.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137818

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


[PATCH] D137818: Add support for querying SubstTemplateTypeParm types

2022-11-19 Thread Anders Langlands via Phabricator via cfe-commits
anderslanglands added a comment.

Arg just noticed an issue: clang_Type_getReplacementType should be in the 
LLVM_16 block in libclang.map not in the LLVM_13 block. I've blown away my 
local branch so don't know how to fix the patch. Shall I just make a new patch 
once this is merged?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137818

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


[PATCH] D137818: Add support for querying SubstTemplateTypeParm types

2022-11-19 Thread Anders Langlands via Phabricator via cfe-commits
anderslanglands added a comment.

Great, thanks! I've got a couple more things to land once this is merged and 
I've cleaned them up. Do you wanna show me how to do the merge myself?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137818

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


[PATCH] D137818: Add support for querying SubstTemplateTypeParm types

2022-11-18 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137818

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


[PATCH] D137818: Add support for querying SubstTemplateTypeParm types

2022-11-17 Thread Anders Langlands via Phabricator via cfe-commits
anderslanglands updated this revision to Diff 476261.
anderslanglands added a comment.

Added release note, incorporated other review notes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137818

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/test/Index/print-type.cpp
  clang/tools/libclang/CXType.cpp
  clang/tools/libclang/libclang.map

Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -164,6 +164,7 @@
 clang_Type_getObjCProtocolDecl;
 clang_Type_getObjCTypeArg;
 clang_Type_getOffsetOf;
+clang_Type_getReplacementType;
 clang_Type_getSizeOf;
 clang_Type_getTemplateArgumentAsType;
 clang_Type_getValueType;
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -118,13 +118,13 @@
 TKCASE(Attributed);
 TKCASE(BTFTagAttributed);
 TKCASE(Atomic);
+TKCASE(SubstTemplateTypeParm);
 default:
   return CXType_Unexposed;
   }
 #undef TKCASE
 }
 
-
 CXType cxtype::MakeCXType(QualType T, CXTranslationUnit TU) {
   CXTypeKind TK = CXType_Invalid;
 
@@ -635,6 +635,7 @@
 TKIND(OCLQueue);
 TKIND(OCLReserveID);
 TKIND(Atomic);
+TKIND(SubstTemplateTypeParm);
   }
 #undef TKIND
   return cxstring::createRef(s);
@@ -1355,3 +1356,11 @@
   const auto *AT = T->castAs();
   return MakeCXType(AT->getValueType(), GetTU(CT));
 }
+
+CXType clang_Type_getReplacementType(CXType CT) {
+  QualType T = GetQualType(CT);
+
+  const auto *ST =
+  !T.isNull() ? T->getAs() : nullptr;
+  return MakeCXType(ST ? ST->getReplacementType() : QualType(), GetTU(CT));
+}
Index: clang/test/Index/print-type.cpp
===
--- clang/test/Index/print-type.cpp
+++ clang/test/Index/print-type.cpp
@@ -171,7 +171,7 @@
 // CHECK: VarDecl=autoI:54:6 (Definition) [type=int] [typekind=Auto] [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1]
 // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
 // CHECK: VarDecl=autoTbar:55:6 (Definition) [type=int] [typekind=Auto] [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1]
-// CHECK: CallExpr=tbar:36:3 [type=int] [typekind=Unexposed] [canonicaltype=int] [canonicaltypekind=Int] [args= [int] [Int]] [isPOD=1]
+// CHECK: CallExpr=tbar:36:3 [type=int] [typekind=SubstTemplateTypeParm] [canonicaltype=int] [canonicaltypekind=Int] [args= [int] [Int]] [isPOD=1]
 // CHECK: UnexposedExpr=tbar:36:3 [type=int (*)(int)] [typekind=Pointer] [canonicaltype=int (*)(int)] [canonicaltypekind=Pointer] [isPOD=1] [pointeetype=int (int)] [pointeekind=FunctionProto]
 // CHECK: DeclRefExpr=tbar:36:3 RefName=[55:17 - 55:21] RefName=[55:21 - 55:26] [type=int (int)] [typekind=FunctionProto] [canonicaltype=int (int)] [canonicaltypekind=FunctionProto] [isPOD=0]
 // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
Index: clang/include/clang-c/Index.h
===
--- clang/include/clang-c/Index.h
+++ clang/include/clang-c/Index.h
@@ -2789,7 +2789,9 @@
 
   CXType_ExtVector = 176,
   CXType_Atomic = 177,
-  CXType_BTFTagAttributed = 178
+  CXType_BTFTagAttributed = 178,
+  /* Represents a type that has been substituted for a template type parameter. */
+  CXType_SubstTemplateTypeParm = 179
 };
 
 /**
@@ -3447,6 +3449,13 @@
  */
 CINDEX_LINKAGE CXType clang_Type_getValueType(CXType CT);
 
+/**
+ * Gets the replacement type for a SubstTemplateTypeParm type.
+ *
+ * If any other type kind is passed in, an invalid type is returned.
+ */
+CINDEX_LINKAGE CXType clang_Type_getReplacementType(CXType CT);
+
 /**
  * Return the offset of the field represented by the Cursor.
  *
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -795,6 +795,10 @@
   ``clang_Cursor_getTemplateArgumentType``, ``clang_Cursor_getTemplateArgumentValue`` and 
   ``clang_Cursor_getTemplateArgumentUnsignedValue`` now work on struct, class,
   and partial template specialization cursors in addition to function cursors.
+- Added ``CXType_SubstTemplateTypeParm`` to ``CXTypeKind``, which identifies a type that 
+  is a replacement for a template type parameter (previously reported a ``CXType_Unexposed``).
+- Introduced the new function ``clang_Type_getReplacementType`` which gets the type replacing
+  the template type parameter when type kind is ``CXType_SubstTemplateTypeParm``.
 
 Static Analyzer
 ---
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137818: Add support for querying SubstTemplateTypeParm types

2022-11-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thanks for this! You should also add a release note about the new functionality.




Comment at: clang/include/clang-c/Index.h:2793-2794
+  CXType_BTFTagAttributed = 178,
+  /* Represents a type that as been substituted for a template type parameter 
*/
+  CXType_SubstTemplateTypeParm = 179
 };





Comment at: clang/tools/libclang/CXType.cpp:129-130
+static CXTypeKind GetSubstTemplateTypeParmTypeKind(const 
SubstTemplateTypeParmType* TP) {
+  const QualType RT = TP->getReplacementType();
+  return GetTypeKind(RT);
+}





Comment at: clang/tools/libclang/CXType.cpp:1368-1372
+  if (T.isNull() || T->getTypeClass() != Type::SubstTemplateTypeParm)
+return MakeCXType(QualType(), GetTU(CT));
+
+  const auto *ST = T->castAs();
+  return MakeCXType(ST->getReplacementType(), GetTU(CT));





Comment at: clang/tools/libclang/CXType.cpp:1374
+}
\ No newline at end of file


Can you add the newline back?



Comment at: clang/tools/libclang/libclang.map:170
 clang_Type_getValueType;
+clang_Type_getReplacementType;
 clang_Type_isTransparentTagTypedef;

You should keep this in alphabetical order.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137818

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


[PATCH] D137818: Add support for querying SubstTemplateTypeParm types

2022-11-11 Thread Anders Langlands via Phabricator via cfe-commits
anderslanglands created this revision.
anderslanglands added reviewers: tbaeder, aaron.ballman.
Herald added subscribers: arphaman, kristof.beyls.
Herald added a project: All.
anderslanglands requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Adds CXType_SubstTemplateTypeParm and clang_Type_getReplacementType()


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137818

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


Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -167,6 +167,7 @@
 clang_Type_getSizeOf;
 clang_Type_getTemplateArgumentAsType;
 clang_Type_getValueType;
+clang_Type_getReplacementType;
 clang_Type_isTransparentTagTypedef;
 clang_Type_visitFields;
 clang_VerbatimBlockLineComment_getText;
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -118,12 +118,17 @@
 TKCASE(Attributed);
 TKCASE(BTFTagAttributed);
 TKCASE(Atomic);
+TKCASE(SubstTemplateTypeParm);
 default:
   return CXType_Unexposed;
   }
 #undef TKCASE
 }
 
+static CXTypeKind GetSubstTemplateTypeParmTypeKind(const 
SubstTemplateTypeParmType* TP) {
+  const QualType RT = TP->getReplacementType();
+  return GetTypeKind(RT);
+}
 
 CXType cxtype::MakeCXType(QualType T, CXTranslationUnit TU) {
   CXTypeKind TK = CXType_Invalid;
@@ -635,6 +640,7 @@
 TKIND(OCLQueue);
 TKIND(OCLReserveID);
 TKIND(Atomic);
+TKIND(SubstTemplateTypeParm);
   }
 #undef TKIND
   return cxstring::createRef(s);
@@ -1355,3 +1361,13 @@
   const auto *AT = T->castAs();
   return MakeCXType(AT->getValueType(), GetTU(CT));
 }
+
+CXType clang_Type_getReplacementType(CXType CT) {
+  QualType T = GetQualType(CT);
+
+  if (T.isNull() || T->getTypeClass() != Type::SubstTemplateTypeParm)
+return MakeCXType(QualType(), GetTU(CT));
+
+  const auto *ST = T->castAs();
+  return MakeCXType(ST->getReplacementType(), GetTU(CT));
+}
\ No newline at end of file
Index: clang/test/Index/print-type.cpp
===
--- clang/test/Index/print-type.cpp
+++ clang/test/Index/print-type.cpp
@@ -171,7 +171,7 @@
 // CHECK: VarDecl=autoI:54:6 (Definition) [type=int] [typekind=Auto] 
[canonicaltype=int] [canonicaltypekind=Int] [isPOD=1]
 // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
 // CHECK: VarDecl=autoTbar:55:6 (Definition) [type=int] [typekind=Auto] 
[canonicaltype=int] [canonicaltypekind=Int] [isPOD=1]
-// CHECK: CallExpr=tbar:36:3 [type=int] [typekind=Unexposed] 
[canonicaltype=int] [canonicaltypekind=Int] [args= [int] [Int]] [isPOD=1]
+// CHECK: CallExpr=tbar:36:3 [type=int] [typekind=SubstTemplateTypeParm] 
[canonicaltype=int] [canonicaltypekind=Int] [args= [int] [Int]] [isPOD=1]
 // CHECK: UnexposedExpr=tbar:36:3 [type=int (*)(int)] [typekind=Pointer] 
[canonicaltype=int (*)(int)] [canonicaltypekind=Pointer] [isPOD=1] 
[pointeetype=int (int)] [pointeekind=FunctionProto]
 // CHECK: DeclRefExpr=tbar:36:3 RefName=[55:17 - 55:21] RefName=[55:21 - 
55:26] [type=int (int)] [typekind=FunctionProto] [canonicaltype=int (int)] 
[canonicaltypekind=FunctionProto] [isPOD=0]
 // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
Index: clang/include/clang-c/Index.h
===
--- clang/include/clang-c/Index.h
+++ clang/include/clang-c/Index.h
@@ -2789,7 +2789,9 @@
 
   CXType_ExtVector = 176,
   CXType_Atomic = 177,
-  CXType_BTFTagAttributed = 178
+  CXType_BTFTagAttributed = 178,
+  /* Represents a type that as been substituted for a template type parameter 
*/
+  CXType_SubstTemplateTypeParm = 179
 };
 
 /**
@@ -3447,6 +3449,13 @@
  */
 CINDEX_LINKAGE CXType clang_Type_getValueType(CXType CT);
 
+/**
+ * Gets the replacement type for a SubstTemplateTypeParm type.
+ *
+ * If any other type kind is passed in, an invalid type is returned.
+ */
+CINDEX_LINKAGE CXType clang_Type_getReplacementType(CXType CT);
+
 /**
  * Return the offset of the field represented by the Cursor.
  *


Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -167,6 +167,7 @@
 clang_Type_getSizeOf;
 clang_Type_getTemplateArgumentAsType;
 clang_Type_getValueType;
+clang_Type_getReplacementType;
 clang_Type_isTransparentTagTypedef;
 clang_Type_visitFields;
 clang_VerbatimBlockLineComment_getText;
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp