[clang] 4a9dc94 - [clang] Test for AST Dumping of the template variables

Tomasz Kamiński via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 27 01:11:12 PDT 2023


Author: Tomasz Kamiński
Date: 2023-03-27T09:53:47+02:00
New Revision: 4a9dc94d336ab0c68d718db21d1666ac19868642

URL: https://github.com/llvm/llvm-project/commit/4a9dc94d336ab0c68d718db21d1666ac19868642
DIFF: https://github.com/llvm/llvm-project/commit/4a9dc94d336ab0c68d718db21d1666ac19868642.diff

LOG: [clang] Test for AST Dumping of the template variables

They illustrate unstable behavior of the https://reviews.llvm.org/D139705 after serialization.
(`#61680 <https://github.com/llvm/llvm-project/issues/61680>`).

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D146784

Added: 
    

Modified: 
    clang/test/AST/ast-dump-template-decls.cpp

Removed: 
    


################################################################################
diff  --git a/clang/test/AST/ast-dump-template-decls.cpp b/clang/test/AST/ast-dump-template-decls.cpp
index 49760d17c7f22..fe367aefa6020 100644
--- a/clang/test/AST/ast-dump-template-decls.cpp
+++ b/clang/test/AST/ast-dump-template-decls.cpp
@@ -1,12 +1,12 @@
 // Test without serialization:
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -ast-dump %s \
-// RUN: | FileCheck -strict-whitespace %s
+// RUN: | FileCheck -strict-whitespace %s --check-prefix=DIRECT
 //
 // Test with serialization:
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -x c++ -std=c++17 -triple x86_64-unknown-unknown -include-pch %t -ast-dump-all /dev/null \
 // RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
-// RUN: | FileCheck --strict-whitespace %s
+// RUN: | FileCheck --strict-whitespace %s --check-prefix=SERIALIZED
 
 template <typename Ty>
 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <{{.*}}:1, line:[[@LINE+2]]:10> col:6 a
@@ -178,3 +178,80 @@ using test1 = D<E, int>;
 // CHECK-NEXT: `-RecordType 0x{{[^ ]*}} 'subst_default_argument::A<int>'
 // CHECK-NEXT:   `-ClassTemplateSpecialization 0x{{[^ ]*}} 'A'
 } // namespace subst_default_argument
+
+namespace D146733 {
+template<class T>
+T unTempl = 1;
+// CHECK:VarTemplateDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:13> col:3 unTempl
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:10, col:16> col:16 referenced class depth 0 index 0 T
+// CHECK-NEXT: |-VarDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, col:13> col:3 unTempl 'T' cinit
+// CHECK-NEXT: | `-IntegerLiteral 0x{{[^ ]*}} <col:13> 'int' 1
+
+template<>
+int unTempl<int>;
+// FIXME (#61680) - serializing and loading AST should not affect reported source range
+// DIRECT:     VarTemplateSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:16> col:5 unTempl 'int'
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:5> col:5 unTempl 'int'
+// CHECK-NEXT: `-TemplateArgument type 'int'
+// CHECK-NEXT: `-BuiltinType 0x{{[^ ]*}} 'int'
+
+template<>
+float unTempl<float> = 1;
+// FIXME (#61680) - serializing and loading AST should not affect reported source range
+// DIRECT:     VarTemplateSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:20> col:7 unTempl 'float' cinit
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:24> col:7 unTempl 'float' cinit
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
+// CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}} <col:24> 'float' <IntegralToFloating>
+// CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}} <col:24> 'int' 1
+
+template<class T, class U>
+T binTempl = 1;
+// CHECK:      VarTemplateDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:14> col:3 binTempl
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:10, col:16> col:16 referenced class depth 0 index 0 T
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}} <col:19, col:25> col:25 class depth 0 index 1 U
+// CHECK-NEXT: |-VarDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, col:14> col:3 binTempl 'T' cinit
+// CHECK-NEXT: | `-IntegerLiteral 0x{{[^ ]*}} <col:14> 'int' 1
+
+template<class U>
+int binTempl<int, U>;
+// CHECK:      VarTemplatePartialSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:20> col:5 binTempl 'int'
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:10, col:16> col:16 referenced class depth 0 index 0 U
+// CHECK-NEXT: |-TemplateArgument type 'int'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
+// CHECK-NEXT: `-TemplateArgument type 'type-parameter-0-0'
+// CHECK-NEXT: `-TemplateTypeParmType 0x{{[^ ]*}} 'type-parameter-0-0' dependent depth 0 index 0
+
+template<class U>
+float binTempl<float, U> = 1;
+// CHECK:      VarTemplatePartialSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:24> col:7 binTempl 'float' cinit
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:10, col:16> col:16 referenced class depth 0 index 0 U
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
+// CHECK-NEXT: |-TemplateArgument type 'type-parameter-0-0'
+// CHECK-NEXT: | `-TemplateTypeParmType 0x{{[^ ]*}} 'type-parameter-0-0' dependent depth 0 index 0
+// CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}} <line:{{[0-9]+}}:28> 'float' <IntegralToFloating>
+// CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}} <col:28> 'int' 1
+
+template<>
+int binTempl<int, int>;
+// FIXME (#61680) - serializing and loading AST should not affect reported source range
+// DIRECT:     VarTemplateSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:22> col:5 binTempl 'int'
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:5> col:5 binTempl 'int'
+// CHECK-NEXT: |-TemplateArgument type 'int'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
+// CHECK-NEXT: `-TemplateArgument type 'int'
+// CHECK-NEXT: `-BuiltinType 0x{{[^ ]*}} 'int'
+
+template<>
+float binTempl<float, float> = 1;
+// FIXME (#61680) - serializing and loading AST should not affect reported source range
+// DIRECT:    VarTemplateSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:28> col:7 binTempl 'float' cinit
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}} <line:{{[0-9]+}}:1, line:{{[0-9]+}}:32> col:7 binTempl 'float' cinit
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
+// CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}} <col:32> 'float' <IntegralToFloating>
+// CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}} <col:32> 'int' 1
+}


        


More information about the cfe-commits mailing list