[clang] 3bfafc4 - [clang][AST] TextNodeDumper learned to output template specialization kind
Timo Stripf via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 15 08:58:14 PDT 2023
Author: Timo Stripf
Date: 2023-08-15T15:46:31Z
New Revision: 3bfafc4f22870d00631fe1466676007d73bf6794
URL: https://github.com/llvm/llvm-project/commit/3bfafc4f22870d00631fe1466676007d73bf6794
DIFF: https://github.com/llvm/llvm-project/commit/3bfafc4f22870d00631fe1466676007d73bf6794.diff
LOG: [clang][AST] TextNodeDumper learned to output template specialization kind
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D157705
Added:
Modified:
clang/include/clang/AST/TextNodeDumper.h
clang/lib/AST/TextNodeDumper.cpp
clang/test/AST/HLSL/this-reference-template.hlsl
clang/test/AST/ast-dump-decl.cpp
clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
clang/test/SemaCXX/lambda-conversion-op-cc.cpp
clang/test/SemaOpenCLCXX/address-space-deduction.clcpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/TextNodeDumper.h b/clang/include/clang/AST/TextNodeDumper.h
index e8480543a3b87e..771dab01c2ba04 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -202,6 +202,7 @@ class TextNodeDumper
void dumpName(const NamedDecl *ND);
void dumpAccessSpecifier(AccessSpecifier AS);
void dumpCleanupObject(const ExprWithCleanups::CleanupObject &C);
+ void dumpTemplateSpecializationKind(TemplateSpecializationKind TSK);
void dumpDeclRef(const Decl *D, StringRef Label = {});
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index d6c72d6207df22..a562e6d8140115 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -734,6 +734,26 @@ void TextNodeDumper::dumpCleanupObject(
llvm_unreachable("unexpected cleanup type");
}
+void clang::TextNodeDumper::dumpTemplateSpecializationKind(
+ TemplateSpecializationKind TSK) {
+ switch (TSK) {
+ case TSK_Undeclared:
+ break;
+ case TSK_ImplicitInstantiation:
+ OS << " implicit_instantiation";
+ break;
+ case TSK_ExplicitSpecialization:
+ OS << " explicit_specialization";
+ break;
+ case TSK_ExplicitInstantiationDeclaration:
+ OS << " explicit_instantiation_declaration";
+ break;
+ case TSK_ExplicitInstantiationDefinition:
+ OS << " explicit_instantiation_definition";
+ break;
+ }
+}
+
void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef Label) {
if (!D)
return;
@@ -1744,6 +1764,7 @@ void TextNodeDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
void TextNodeDumper::VisitFunctionDecl(const FunctionDecl *D) {
dumpName(D);
dumpType(D->getType());
+ dumpTemplateSpecializationKind(D->getTemplateSpecializationKind());
StorageClass SC = D->getStorageClass();
if (SC != SC_None)
@@ -1840,6 +1861,7 @@ void TextNodeDumper::VisitFieldDecl(const FieldDecl *D) {
void TextNodeDumper::VisitVarDecl(const VarDecl *D) {
dumpName(D);
dumpType(D->getType());
+ dumpTemplateSpecializationKind(D->getTemplateSpecializationKind());
StorageClass SC = D->getStorageClass();
if (SC != SC_None)
OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
@@ -2028,6 +2050,9 @@ void TextNodeDumper::VisitTypeAliasTemplateDecl(
void TextNodeDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
VisitRecordDecl(D);
+ if (const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D))
+ dumpTemplateSpecializationKind(CTSD->getSpecializationKind());
+
if (!D->isCompleteDefinition())
return;
diff --git a/clang/test/AST/HLSL/this-reference-template.hlsl b/clang/test/AST/HLSL/this-reference-template.hlsl
index c27d69d36ca3e9..3b7fba3efdc747 100644
--- a/clang/test/AST/HLSL/this-reference-template.hlsl
+++ b/clang/test/AST/HLSL/this-reference-template.hlsl
@@ -32,13 +32,13 @@ void main() {
// CHECK-NEXT:-MemberExpr 0x{{[0-9A-Fa-f]+}} <col:12> 'V' lvalue .Second 0x{{[0-9A-Fa-f]+}}
// CHECK-NEXT:-CXXThisExpr 0x{{[0-9A-Fa-f]+}} <col:12> 'Pair<K, V>' lvalue implicit this
-// CHECK: -CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <line:8:3, line:10:3> line:8:5 used getFirst 'int ()' implicit-inline
+// CHECK: -CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <line:8:3, line:10:3> line:8:5 used getFirst 'int ()' implicit_instantiation implicit-inline
// CHECK-NEXT:-CompoundStmt 0x{{[0-9A-Fa-f]+}} <col:16, line:10:3>
// CHECK-NEXT:-ReturnStmt 0x{{[0-9A-Fa-f]+}} <line:9:4, col:16>
// CHECK-NEXT:-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}} <col:11, col:16> 'int':'int' <LValueToRValue>
// CHECK-NEXT:-MemberExpr 0x{{[0-9A-Fa-f]+}} <col:11, col:16> 'int':'int' lvalue .First 0x{{[0-9A-Fa-f]+}}
// CHECK-NEXT:-CXXThisExpr 0x{{[0-9A-Fa-f]+}} <col:11> 'Pair<int, float>' lvalue this
-// CHECK-NEXT:-CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <line:12:3, line:14:3> line:12:5 used getSecond 'float ()' implicit-inline
+// CHECK-NEXT:-CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <line:12:3, line:14:3> line:12:5 used getSecond 'float ()' implicit_instantiation implicit-inline
// CHECK-NEXT:-CompoundStmt 0x{{[0-9A-Fa-f]+}} <col:17, line:14:3>
// CHECK-NEXT:-ReturnStmt 0x{{[0-9A-Fa-f]+}} <line:13:5, col:12>
// CHECK-NEXT:-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}} <col:12> 'float':'float' <LValueToRValue>
diff --git a/clang/test/AST/ast-dump-decl.cpp b/clang/test/AST/ast-dump-decl.cpp
index 276a2095bec7c2..e822b5fa44c55f 100644
--- a/clang/test/AST/ast-dump-decl.cpp
+++ b/clang/test/AST/ast-dump-decl.cpp
@@ -377,8 +377,8 @@ namespace testClassTemplateDecl {
// CHECK-NEXT: | `-CXXRecord 0x{{.+}} 'C'
// CHECK-NEXT: |-CXXRecordDecl 0x{{.+}} <line:[[@LINE-104]]:24, col:30> col:30 implicit class TestClassTemplate
// CHECK-NEXT: |-AccessSpecDecl 0x{{.+}} <line:[[@LINE-104]]:3, col:9> col:3 public
-// CHECK-NEXT: |-CXXConstructorDecl 0x{{.+}} <line:[[@LINE-104]]:5, col:23> col:5 TestClassTemplate 'void ()'
-// CHECK-NEXT: |-CXXDestructorDecl 0x{{.+}} <line:[[@LINE-104]]:5, col:24> col:5 ~TestClassTemplate 'void ()' noexcept-unevaluated 0x{{.+}}
+// CHECK-NEXT: |-CXXConstructorDecl 0x{{.+}} <line:[[@LINE-104]]:5, col:23> col:5 TestClassTemplate 'void ()' explicit_instantiation_declaration
+// CHECK-NEXT: |-CXXDestructorDecl 0x{{.+}} <line:[[@LINE-104]]:5, col:24> col:5 ~TestClassTemplate 'void ()' explicit_instantiation_declaration noexcept-unevaluated 0x{{.+}}
// CHECK-NEXT: |-CXXMethodDecl 0x{{.+}} <line:[[@LINE-104]]:5, col:11> col:9 j 'int ()'
// CHECK-NEXT: `-FieldDecl 0x{{.+}} <line:[[@LINE-104]]:5, col:9> col:9 i 'int'
@@ -395,9 +395,9 @@ namespace testClassTemplateDecl {
// CHECK-NEXT: | `-CXXRecord 0x{{.+}} 'D'
// CHECK-NEXT: |-CXXRecordDecl 0x{{.+}} <line:[[@LINE-122]]:24, col:30> col:30 implicit class TestClassTemplate
// CHECK-NEXT: |-AccessSpecDecl 0x{{.+}} <line:[[@LINE-122]]:3, col:9> col:3 public
-// CHECK-NEXT: |-CXXConstructorDecl 0x{{.+}} <line:[[@LINE-122]]:5, col:23> col:5 TestClassTemplate 'void ()'
-// CHECK-NEXT: |-CXXDestructorDecl 0x{{.+}} <line:[[@LINE-122]]:5, col:24> col:5 ~TestClassTemplate 'void ()' noexcept-unevaluated 0x{{.+}}
-// CHECK-NEXT: |-CXXMethodDecl 0x{{.+}} <line:[[@LINE-122]]:5, col:11> col:9 j 'int ()'
+// CHECK-NEXT: |-CXXConstructorDecl 0x{{.+}} <line:[[@LINE-122]]:5, col:23> col:5 TestClassTemplate 'void ()' implicit_instantiation
+// CHECK-NEXT: |-CXXDestructorDecl 0x{{.+}} <line:[[@LINE-122]]:5, col:24> col:5 ~TestClassTemplate 'void ()' implicit_instantiation noexcept-unevaluated 0x{{.+}}
+// CHECK-NEXT: |-CXXMethodDecl 0x{{.+}} <line:[[@LINE-122]]:5, col:11> col:9 j 'int ()' implicit_instantiation
// CHECK-NEXT: `-FieldDecl 0x{{.+}} <line:[[@LINE-122]]:5, col:9> col:9 i 'int'
// CHECK: ClassTemplateDecl 0x{{.+}} <{{.+}}:[[@LINE-106]]:3, line:[[@LINE-104]]:3> line:[[@LINE-106]]:44 TestClassTemplatePartial
@@ -608,14 +608,14 @@ namespace testCanonicalTemplate {
// CHECK: VarTemplateDecl 0x{{.+}} <{{.+}}:[[@LINE-11]]:7, col:43> col:43 TestVarTemplate
// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{.+}} <col:16, col:25> col:25 referenced typename depth 0 index 0 T
// CHECK-NEXT: |-VarDecl 0x{{.+}} <col:28, col:43> col:43 TestVarTemplate 'const T' static
- // CHECK-NEXT: |-VarTemplateSpecializationDecl 0x{{.+}} parent 0x{{.+}} prev 0x{{.+}} <line:[[@LINE-11]]:3, col:34> col:14 referenced TestVarTemplate 'const int':'const int' cinit
+ // CHECK-NEXT: |-VarTemplateSpecializationDecl 0x{{.+}} parent 0x{{.+}} prev 0x{{.+}} <line:[[@LINE-11]]:3, col:34> col:14 referenced TestVarTemplate 'const int':'const int' implicit_instantiation cinit
// CHECK-NEXT: | |-TemplateArgument type 'int'
// CHECK-NEXT: | | `-BuiltinType 0x{{.+}} 'int'
// CHECK-NEXT: | `-InitListExpr 0x{{.+}} <col:32, col:34> 'int':'int'
- // CHECK-NEXT: `-VarTemplateSpecializationDecl 0x{{.+}} <line:[[@LINE-18]]:28, col:43> col:43 referenced TestVarTemplate 'const int':'const int' static
+ // CHECK-NEXT: `-VarTemplateSpecializationDecl 0x{{.+}} <line:[[@LINE-18]]:28, col:43> col:43 referenced TestVarTemplate 'const int':'const int' implicit_instantiation static
// CHECK-NEXT: `-TemplateArgument type 'int'
- // CHECK: VarTemplateSpecializationDecl 0x{{.+}} <{{.+}}:[[@LINE-21]]:28, col:43> col:43 referenced TestVarTemplate 'const int':'const int' static
+ // CHECK: VarTemplateSpecializationDecl 0x{{.+}} <{{.+}}:[[@LINE-21]]:28, col:43> col:43 referenced TestVarTemplate 'const int':'const int' implicit_instantiation static
// CHECK-NEXT:`-TemplateArgument type 'int'
// CHECK-NEXT: `-BuiltinType 0x{{.+}} 'int'
@@ -626,7 +626,7 @@ namespace testCanonicalTemplate {
// CHECK-NEXT: |-VarTemplateSpecialization 0x{{.+}} 'TestVarTemplate' 'const int':'const int'
// CHECK-NEXT: `-VarTemplateSpecialization 0x{{.+}} 'TestVarTemplate' 'const int':'const int'
- // CHECK: VarTemplateSpecializationDecl 0x{{.+}} parent 0x{{.+}} prev 0x{{.+}} <{{.+}}:[[@LINE-29]]:3, col:34> col:14 referenced TestVarTemplate 'const int':'const int' cinit
+ // CHECK: VarTemplateSpecializationDecl 0x{{.+}} parent 0x{{.+}} prev 0x{{.+}} <{{.+}}:[[@LINE-29]]:3, col:34> col:14 referenced TestVarTemplate 'const int':'const int' implicit_instantiation cinit
// CHECK-NEXT: |-TemplateArgument type 'int'
// CHECK-NEXT: | `-BuiltinType 0x{{.+}} 'int'
// CHECK-NEXT: `-InitListExpr 0x{{.+}} <col:32, col:34> 'int':'int'
diff --git a/clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp b/clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
index 2cf404d490a699..ef1d2033c5d10e 100644
--- a/clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
+++ b/clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
@@ -184,7 +184,7 @@ int test(float &&f, short &&s) {
// CHECK-NEXT: | | `-ReturnStmt [[ADDR_39:0x[a-z0-9]*]] <line:13:3, col:33>
// CHECK-NEXT: | | `-CXXStaticCastExpr [[ADDR_40:0x[a-z0-9]*]] <col:10, col:33> '_Up':'typename remove_reference<_Tp>::type' xvalue static_cast<_Up &&> <Dependent>
// CHECK-NEXT: | | `-DeclRefExpr [[ADDR_41:0x[a-z0-9]*]] <col:30> '_Tp' {{.*}}ParmVar [[ADDR_34]] '__t' '_Tp &&'
-// CHECK-NEXT: | |-FunctionDecl [[ADDR_42:0x[a-z0-9]*]] <line:10:1, line:14:1> line:11:1 used move 'typename remove_reference<float &>::type &&(float &)' inline
+// CHECK-NEXT: | |-FunctionDecl [[ADDR_42:0x[a-z0-9]*]] <line:10:1, line:14:1> line:11:1 used move 'typename remove_reference<float &>::type &&(float &)' implicit_instantiation inline
// CHECK-NEXT: | | |-TemplateArgument type 'float &'
// CHECK-NEXT: | | | `-LValueReferenceType [[ADDR_7]] 'float &'
// CHECK-NEXT: | | | `-BuiltinType [[ADDR_8]] 'float'
@@ -201,7 +201,7 @@ int test(float &&f, short &&s) {
// CHECK-NEXT: | | `-ReturnStmt [[ADDR_49:0x[a-z0-9]*]] <line:13:3, col:33>
// CHECK-NEXT: | | `-CXXStaticCastExpr [[ADDR_50:0x[a-z0-9]*]] <col:10, col:33> '_Up':'float' xvalue static_cast<_Up &&> <NoOp>
// CHECK-NEXT: | | `-DeclRefExpr [[ADDR_51:0x[a-z0-9]*]] <col:30> 'float' {{.*}}ParmVar [[ADDR_43]] '__t' 'float &'
-// CHECK-NEXT: | `-FunctionDecl [[ADDR_52:0x[a-z0-9]*]] <line:10:1, line:14:1> line:11:1 used move 'typename remove_reference<short &>::type &&(short &)' inline
+// CHECK-NEXT: | `-FunctionDecl [[ADDR_52:0x[a-z0-9]*]] <line:10:1, line:14:1> line:11:1 used move 'typename remove_reference<short &>::type &&(short &)' implicit_instantiation inline
// CHECK-NEXT: | |-TemplateArgument type 'short &'
// CHECK-NEXT: | | `-LValueReferenceType [[ADDR_15]] 'short &'
// CHECK-NEXT: | | `-BuiltinType [[ADDR_16]] 'short'
diff --git a/clang/test/SemaCXX/lambda-conversion-op-cc.cpp b/clang/test/SemaCXX/lambda-conversion-op-cc.cpp
index 77aa18cc887592..16ca5535019dff 100644
--- a/clang/test/SemaCXX/lambda-conversion-op-cc.cpp
+++ b/clang/test/SemaCXX/lambda-conversion-op-cc.cpp
@@ -67,11 +67,11 @@ void useage() {
//
// CHECK: FunctionTemplateDecl {{.*}} operator()
// LIN64: CXXMethodDecl {{.*}} operator() 'auto (auto) const' inline
- // LIN64: CXXMethodDecl {{.*}} operator() 'void (char) const' inline
- // LIN64: CXXMethodDecl {{.*}} operator() 'void (int) const' inline
+ // LIN64: CXXMethodDecl {{.*}} operator() 'void (char) const' implicit_instantiation inline
+ // LIN64: CXXMethodDecl {{.*}} operator() 'void (int) const' implicit_instantiation inline
// WIN32: CXXMethodDecl {{.*}} operator() 'auto (auto) __attribute__((thiscall)) const' inline
- // WIN32: CXXMethodDecl {{.*}} operator() 'void (char) __attribute__((thiscall)) const' inline
- // WIN32: CXXMethodDecl {{.*}} operator() 'void (int) __attribute__((thiscall)) const' inline
+ // WIN32: CXXMethodDecl {{.*}} operator() 'void (char) __attribute__((thiscall)) const' implicit_instantiation inline
+ // WIN32: CXXMethodDecl {{.*}} operator() 'void (int) __attribute__((thiscall)) const' implicit_instantiation inline
//
// NODEF: FunctionTemplateDecl {{.*}} operator auto (*)(type-parameter-0-0)
// VECDEF: FunctionTemplateDecl {{.*}} operator auto (*)(type-parameter-0-0) __attribute__((vectorcall))
@@ -108,8 +108,8 @@ void useage() {
// CHECK: LambdaExpr
// CHECK: FunctionTemplateDecl {{.*}} operator()
// CHECK: CXXMethodDecl {{.*}} operator() 'auto (auto) __attribute__((vectorcall)) const' inline
- // CHECK: CXXMethodDecl {{.*}} operator() 'void (char) __attribute__((vectorcall)) const' inline
- // CHECK: CXXMethodDecl {{.*}} operator() 'void (int) __attribute__((vectorcall)) const' inline
+ // CHECK: CXXMethodDecl {{.*}} operator() 'void (char) __attribute__((vectorcall)) const' implicit_instantiation inline
+ // CHECK: CXXMethodDecl {{.*}} operator() 'void (int) __attribute__((vectorcall)) const' implicit_instantiation inline
// CHECK: FunctionTemplateDecl {{.*}} operator auto (*)(type-parameter-0-0) __attribute__((vectorcall))
// LIN64: CXXConversionDecl {{.*}} operator auto (*)(type-parameter-0-0) __attribute__((vectorcall)) 'auto (*() const noexcept)(auto) __attribute__((vectorcall))'
// LIN64: CXXConversionDecl {{.*}} operator auto (*)(char) __attribute__((vectorcall)) 'void (*() const noexcept)(char) __attribute__((vectorcall))'
diff --git a/clang/test/SemaOpenCLCXX/address-space-deduction.clcpp b/clang/test/SemaOpenCLCXX/address-space-deduction.clcpp
index 15b3976930abfb..3c801f2c4db763 100644
--- a/clang/test/SemaOpenCLCXX/address-space-deduction.clcpp
+++ b/clang/test/SemaOpenCLCXX/address-space-deduction.clcpp
@@ -6,7 +6,7 @@
constexpr int foo = 0;
//CHECK: |-VarDecl {{.*}} foo1 'T' cinit
-//CHECK: `-VarTemplateSpecializationDecl {{.*}} used foo1 '__global long':'__global long' cinit
+//CHECK: `-VarTemplateSpecializationDecl {{.*}} used foo1 '__global long':'__global long' implicit_instantiation cinit
template <typename T>
T foo1 = 0;
More information about the cfe-commits
mailing list