Debian Codegraph @

clang/test/DebugInfo/CXX/template-parameter.cpp

raw
1 // Test for DebugInfo for Defaulted parameters for C++ templates
2 // Supported: -O0, standalone DI
3
4 // RUN: %clang_cc1 -emit-llvm %std_cxx11-14 -dwarf-version=5 -triple x86_64 %s -O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s --check-prefixes=CHECK,PRE17
5 // RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=5 -triple x86_64 %s -O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s --check-prefixes=CHECK,CXX17
6 // RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=4 -triple x86_64 %s -O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s --check-prefixes=CHECK,CXX17
7 // RUN: %clang_cc1 -emit-llvm %std_cxx20- -dwarf-version=5 -DCXX20=1 -triple x86_64 %s -O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s --check-prefix=CHECK-CXX20
8
9 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
10 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: ![[F1_TYPE:[0-9]+]]
11 // CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], ![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]], ![[FIFTH:[0-9]+]]}
12 // CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}})
13 // CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, value: i32 6)
14 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, value: i8 0)
15 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, value: i1 false)
16 // CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}})
17
18 // CHECK: DILocalVariable(name: "f2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
19 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: ![[F2_TYPE:[0-9]+]]
20 // CHECK: [[F2_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], ![[THIRD:[0-9]+]], ![[FORTH:[0-9]+]], ![[FIFTH:[0-9]+]]}
21 // CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}}, defaulted: true)
22 // CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, defaulted: true, value: i32 3)
23 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, defaulted: true, value: i8 1)
24 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, defaulted: true, value: i1 true)
25 // CHECK: [[FIFTH]] = !DITemplateTypeParameter(name: "d", type: !{{[0-9]*}}, defaulted: true)
26
27 // CHECK: DILocalVariable(name: "b1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
28 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: ![[B1_TYPE:[0-9]+]]
29 // CHECK: [[B1_TYPE]] = !{![[FIRST:[0-9]+]]}
30 // CHECK: [[FIRST]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_template_param, name: "CT", value: !"qux")
31
32 // CHECK: DILocalVariable(name: "b2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
33 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: ![[B2_TYPE:[0-9]+]]
34 // CHECK: [[B2_TYPE]] = !{![[FIRST:[0-9]+]]}
35 // CHECK: [[FIRST]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_template_param, name: "CT", defaulted: true, value: !"bar")
36
37 template <typename T>
38 class bar {
39 };
40
41 template <typename T>
42 class qux {
43 };
44
45 template <typename T = char, int i = 3, bool b = true, int x = sizeof(T),
46 typename d = bar<T>>
47 class foo {
48 };
49
50 template <template <typename T> class CT = bar>
51 class baz {
52 };
53
54 #ifdef CXX20
55 struct non_empty { int mem; int mem2; } ne;
56
57 template<float f = -1.5f, double d = 5.2, int * p = &ne.mem2>
58 class nttp {};
59 nttp<> n1;
60
61 // CHECK-CXX20: DIGlobalVariable(name: "n1", {{.*}}, type: ![[NTTP_TYPE:[0-9]+]]
62 // CHECK-CXX20: [[NTTP_TYPE]] = {{.*}}!DICompositeType({{.*}}name: "nttp
63 // CHECK-CXX20-SAME: templateParams: ![[NTTP_TEMPLATES:[0-9]+]]
64 // CHECK-CXX20: [[NTTP_TEMPLATES]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]], ![[THIRD:[0-9]+]]}
65 // CHECK-CXX20: [[FIRST]] = !DITemplateValueParameter(name: "f"
66 // CHECK-CXX20-SAME: defaulted: true
67 // CHECK-CXX20-SAME: value: float -1.500000e+00
68 // CHECK-CXX20: [[SECOND]] = !DITemplateValueParameter(name: "d"
69 // CHECK-CXX20-SAME: defaulted: true
70 // CHECK-CXX20-SAME: value: double 5.200000e+00
71 // CHECK-CXX20: [[THIRD]] = !DITemplateValueParameter(name: "p"
72 // CHECK-CXX20-SAME: defaulted: true
73 // CHECK-CXX20-SAME: value: ptr getelementptr (i8, ptr @ne, i64 4)
74
75 #endif // CXX20
76
77 int main() {
78 foo<int, 6, false, 3, double> f1;
79 foo<> f2;
80 baz<qux> b1;
81 baz<> b2;
82 return 0;
83 }