annotate clang/test/CodeGenCXX/captured-statements.cpp @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -emit-llvm %s -o %t -debug-info-kind=limited
anatofuz
parents:
diff changeset
2 // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-1
anatofuz
parents:
diff changeset
3 // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-2
anatofuz
parents:
diff changeset
4 // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-3
anatofuz
parents:
diff changeset
5 // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-4
anatofuz
parents:
diff changeset
6 // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-5
anatofuz
parents:
diff changeset
7 // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-6
anatofuz
parents:
diff changeset
8 // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-7
anatofuz
parents:
diff changeset
9
anatofuz
parents:
diff changeset
10 struct Foo {
anatofuz
parents:
diff changeset
11 int x;
anatofuz
parents:
diff changeset
12 float y;
anatofuz
parents:
diff changeset
13 ~Foo() {}
anatofuz
parents:
diff changeset
14 };
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 struct TestClass {
anatofuz
parents:
diff changeset
17 int x;
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 TestClass() : x(0) {};
anatofuz
parents:
diff changeset
20 void MemberFunc() {
anatofuz
parents:
diff changeset
21 Foo f;
anatofuz
parents:
diff changeset
22 #pragma clang __debug captured
anatofuz
parents:
diff changeset
23 {
anatofuz
parents:
diff changeset
24 static double inner = x;
anatofuz
parents:
diff changeset
25 (void)inner;
anatofuz
parents:
diff changeset
26 f.y = x;
anatofuz
parents:
diff changeset
27 }
anatofuz
parents:
diff changeset
28 }
anatofuz
parents:
diff changeset
29 };
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 void test1() {
anatofuz
parents:
diff changeset
32 TestClass c;
anatofuz
parents:
diff changeset
33 c.MemberFunc();
anatofuz
parents:
diff changeset
34 // CHECK-1: %[[Capture:struct\.anon[\.0-9]*]] = type { %struct.TestClass*, %struct.Foo* }
anatofuz
parents:
diff changeset
35 // CHECK-1: [[INNER:@.+]] = {{.+}} global double
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 // CHECK-1: define {{.*}} void @_ZN9TestClass10MemberFuncEv
anatofuz
parents:
diff changeset
38 // CHECK-1: alloca %struct.anon
anatofuz
parents:
diff changeset
39 // CHECK-1: getelementptr inbounds %[[Capture]], %[[Capture]]* %{{[^,]*}}, i32 0, i32 0
anatofuz
parents:
diff changeset
40 // CHECK-1: getelementptr inbounds %[[Capture]], %[[Capture]]* %{{[^,]*}}, i32 0, i32 1
anatofuz
parents:
diff changeset
41 // CHECK-1: store %struct.Foo* %f, %struct.Foo**
anatofuz
parents:
diff changeset
42 // CHECK-1: call void @[[HelperName:[\.A-Za-z0-9_]+]](%[[Capture]]*
anatofuz
parents:
diff changeset
43 // CHECK-1: call {{.*}}FooD1Ev
anatofuz
parents:
diff changeset
44 // CHECK-1: ret
anatofuz
parents:
diff changeset
45 }
anatofuz
parents:
diff changeset
46
anatofuz
parents:
diff changeset
47 // CHECK-1: define internal {{.*}}void @[[HelperName]]
anatofuz
parents:
diff changeset
48 // CHECK-1: getelementptr inbounds %[[Capture]], %[[Capture]]* {{[^,]*}}, i32 0, i32 0
anatofuz
parents:
diff changeset
49 // CHECK-1: call {{.*}}i32 @__cxa_guard_acquire(
anatofuz
parents:
diff changeset
50 // CHECK-1: store double %{{.+}}, double* [[INNER]],
anatofuz
parents:
diff changeset
51 // CHECK-1: call {{.*}}void @__cxa_guard_release(
anatofuz
parents:
diff changeset
52 // CHECK-1: getelementptr inbounds %struct.TestClass, %struct.TestClass* {{[^,]*}}, i32 0, i32 0
anatofuz
parents:
diff changeset
53 // CHECK-1: getelementptr inbounds %[[Capture]], %[[Capture]]* {{[^,]*}}, i32 0, i32 1
anatofuz
parents:
diff changeset
54
anatofuz
parents:
diff changeset
55 void test2(int x) {
anatofuz
parents:
diff changeset
56 int y = [&]() {
anatofuz
parents:
diff changeset
57 #pragma clang __debug captured
anatofuz
parents:
diff changeset
58 {
anatofuz
parents:
diff changeset
59 x++;
anatofuz
parents:
diff changeset
60 }
anatofuz
parents:
diff changeset
61 return x;
anatofuz
parents:
diff changeset
62 }();
anatofuz
parents:
diff changeset
63
anatofuz
parents:
diff changeset
64 // CHECK-2-LABEL: define {{.*}}void @_Z5test2i
anatofuz
parents:
diff changeset
65 // CHECK-2: call {{.*}} @[[Lambda:["$\w]+]]
anatofuz
parents:
diff changeset
66 //
anatofuz
parents:
diff changeset
67 // CHECK-2: define internal {{.*}} @[[Lambda]]
anatofuz
parents:
diff changeset
68 // CHECK-2: call void @[[HelperName:["$_A-Za-z0-9]+]](%[[Capture:.*]]*
anatofuz
parents:
diff changeset
69 //
anatofuz
parents:
diff changeset
70 // CHECK-2: define internal {{.*}}void @[[HelperName]]
anatofuz
parents:
diff changeset
71 // CHECK-2: getelementptr inbounds %[[Capture]], %[[Capture]]*
anatofuz
parents:
diff changeset
72 // CHECK-2: load i32*, i32**
anatofuz
parents:
diff changeset
73 // CHECK-2: load i32, i32*
anatofuz
parents:
diff changeset
74 }
anatofuz
parents:
diff changeset
75
anatofuz
parents:
diff changeset
76 void test3(int x) {
anatofuz
parents:
diff changeset
77 #pragma clang __debug captured
anatofuz
parents:
diff changeset
78 {
anatofuz
parents:
diff changeset
79 x = [=]() { return x + 1; } ();
anatofuz
parents:
diff changeset
80 }
anatofuz
parents:
diff changeset
81 x = [=]() { return x + 1; }();
anatofuz
parents:
diff changeset
82
anatofuz
parents:
diff changeset
83 // CHECK-3: %[[Capture:struct\.anon[\.0-9]*]] = type { i32* }
anatofuz
parents:
diff changeset
84
anatofuz
parents:
diff changeset
85 // CHECK-3-LABEL: define {{.*}}void @_Z5test3i
anatofuz
parents:
diff changeset
86 // CHECK-3: store i32*
anatofuz
parents:
diff changeset
87 // CHECK-3: call void @{{.*}}__captured_stmt
anatofuz
parents:
diff changeset
88 // CHECK-3: ret void
anatofuz
parents:
diff changeset
89 }
anatofuz
parents:
diff changeset
90
anatofuz
parents:
diff changeset
91 void test4() {
anatofuz
parents:
diff changeset
92 #pragma clang __debug captured
anatofuz
parents:
diff changeset
93 {
anatofuz
parents:
diff changeset
94 Foo f;
anatofuz
parents:
diff changeset
95 f.x = 5;
anatofuz
parents:
diff changeset
96 }
anatofuz
parents:
diff changeset
97 // CHECK-4-LABEL: define {{.*}}void @_Z5test4v
anatofuz
parents:
diff changeset
98 // CHECK-4: call void @[[HelperName:[\."$_A-Za-z0-9]+]](%[[Capture:.*]]*
anatofuz
parents:
diff changeset
99 // CHECK-4: ret void
anatofuz
parents:
diff changeset
100 //
anatofuz
parents:
diff changeset
101 // CHECK-4: define internal {{.*}}void @[[HelperName]]
anatofuz
parents:
diff changeset
102 // CHECK-4: store i32 5, i32*
anatofuz
parents:
diff changeset
103 // CHECK-4: call {{.*}}FooD1Ev
anatofuz
parents:
diff changeset
104 }
anatofuz
parents:
diff changeset
105
anatofuz
parents:
diff changeset
106 template <typename T, int id>
anatofuz
parents:
diff changeset
107 void touch(const T &) {}
anatofuz
parents:
diff changeset
108
anatofuz
parents:
diff changeset
109 template <typename T, unsigned id>
anatofuz
parents:
diff changeset
110 void template_capture_var() {
anatofuz
parents:
diff changeset
111 T x;
anatofuz
parents:
diff changeset
112 #pragma clang __debug captured
anatofuz
parents:
diff changeset
113 {
anatofuz
parents:
diff changeset
114 touch<T, id>(x);
anatofuz
parents:
diff changeset
115 }
anatofuz
parents:
diff changeset
116 }
anatofuz
parents:
diff changeset
117
anatofuz
parents:
diff changeset
118 template <typename T, int id>
anatofuz
parents:
diff changeset
119 class Val {
anatofuz
parents:
diff changeset
120 T v;
anatofuz
parents:
diff changeset
121 public:
anatofuz
parents:
diff changeset
122 void set() {
anatofuz
parents:
diff changeset
123 #pragma clang __debug captured
anatofuz
parents:
diff changeset
124 {
anatofuz
parents:
diff changeset
125 touch<T, id>(v);
anatofuz
parents:
diff changeset
126 }
anatofuz
parents:
diff changeset
127 }
anatofuz
parents:
diff changeset
128
anatofuz
parents:
diff changeset
129 template <typename U, int id2>
anatofuz
parents:
diff changeset
130 void foo(U u) {
anatofuz
parents:
diff changeset
131 #pragma clang __debug captured
anatofuz
parents:
diff changeset
132 {
anatofuz
parents:
diff changeset
133 touch<U, id + id2>(u);
anatofuz
parents:
diff changeset
134 }
anatofuz
parents:
diff changeset
135 }
anatofuz
parents:
diff changeset
136 };
anatofuz
parents:
diff changeset
137
anatofuz
parents:
diff changeset
138 void test_capture_var() {
anatofuz
parents:
diff changeset
139 // CHECK-5: define {{.*}} void @_Z20template_capture_varIiLj201EEvv
anatofuz
parents:
diff changeset
140 // CHECK-5-NOT: }
anatofuz
parents:
diff changeset
141 // CHECK-5: store i32*
anatofuz
parents:
diff changeset
142 // CHECK-5: call void @__captured_stmt
anatofuz
parents:
diff changeset
143 // CHECK-5-NEXT: ret void
anatofuz
parents:
diff changeset
144 template_capture_var<int, 201>();
anatofuz
parents:
diff changeset
145
anatofuz
parents:
diff changeset
146 // CHECK-5: define {{.*}} void @_ZN3ValIfLi202EE3setEv
anatofuz
parents:
diff changeset
147 // CHECK-5-NOT: }
anatofuz
parents:
diff changeset
148 // CHECK-5: store %class.Val*
anatofuz
parents:
diff changeset
149 // CHECK-5: call void @__captured_stmt
anatofuz
parents:
diff changeset
150 // CHECK-5-NEXT: ret void
anatofuz
parents:
diff changeset
151 Val<float, 202> Obj;
anatofuz
parents:
diff changeset
152 Obj.set();
anatofuz
parents:
diff changeset
153
anatofuz
parents:
diff changeset
154 // CHECK-5: define {{.*}} void @_ZN3ValIfLi202EE3fooIdLi203EEEvT_
anatofuz
parents:
diff changeset
155 // CHECK-5-NOT: }
anatofuz
parents:
diff changeset
156 // CHECK-5: store %class.Val*
anatofuz
parents:
diff changeset
157 // CHECK-5: store double
anatofuz
parents:
diff changeset
158 // CHECK-5: call void @__captured_stmt
anatofuz
parents:
diff changeset
159 // CHECK-5-NEXT: ret void
anatofuz
parents:
diff changeset
160 Obj.foo<double, 203>(1.0);
anatofuz
parents:
diff changeset
161 }
anatofuz
parents:
diff changeset
162
anatofuz
parents:
diff changeset
163 template <typename T>
anatofuz
parents:
diff changeset
164 void template_capture_lambda() {
anatofuz
parents:
diff changeset
165 T x, y;
anatofuz
parents:
diff changeset
166 [=, &y]() {
anatofuz
parents:
diff changeset
167 #pragma clang __debug captured
anatofuz
parents:
diff changeset
168 {
anatofuz
parents:
diff changeset
169 y += x;
anatofuz
parents:
diff changeset
170 }
anatofuz
parents:
diff changeset
171 }();
anatofuz
parents:
diff changeset
172 }
anatofuz
parents:
diff changeset
173
anatofuz
parents:
diff changeset
174 void test_capture_lambda() {
anatofuz
parents:
diff changeset
175 // CHECK-6: define {{.*}} void @_ZZ23template_capture_lambdaIiEvvENKUlvE_clEv
anatofuz
parents:
diff changeset
176 // CHECK-6-NOT: }
anatofuz
parents:
diff changeset
177 // CHECK-6: store i32*
anatofuz
parents:
diff changeset
178 // CHECK-6: store i32*
anatofuz
parents:
diff changeset
179 // CHECK-6: call void @__captured_stmt
anatofuz
parents:
diff changeset
180 // CHECK-6-NEXT: ret void
anatofuz
parents:
diff changeset
181 template_capture_lambda<int>();
anatofuz
parents:
diff changeset
182 }
anatofuz
parents:
diff changeset
183
anatofuz
parents:
diff changeset
184 inline int test_captured_linkage() {
anatofuz
parents:
diff changeset
185 // CHECK-7: @_ZZ21test_captured_linkagevE1i = linkonce_odr {{(dso_local )?}}global i32 0
anatofuz
parents:
diff changeset
186 int j;
anatofuz
parents:
diff changeset
187 #pragma clang __debug captured
anatofuz
parents:
diff changeset
188 {
anatofuz
parents:
diff changeset
189 static int i = 0;
anatofuz
parents:
diff changeset
190 j = ++i;
anatofuz
parents:
diff changeset
191 }
anatofuz
parents:
diff changeset
192 return j;
anatofuz
parents:
diff changeset
193 }
anatofuz
parents:
diff changeset
194 void call_test_captured_linkage() {
anatofuz
parents:
diff changeset
195 test_captured_linkage();
anatofuz
parents:
diff changeset
196 }
anatofuz
parents:
diff changeset
197
anatofuz
parents:
diff changeset
198 // CHECK-1-DAG: !DILocalVariable(name: "this", {{.*}}, flags: DIFlagArtificial | DIFlagObjectPointer)
anatofuz
parents:
diff changeset
199 // CHECK-1-DAG: !DILocalVariable(name: "__context", {{.*}}, flags: DIFlagArtificial)
anatofuz
parents:
diff changeset
200 // CHECK-2-DAG: !DILocalVariable(name: "this", {{.*}}, flags: DIFlagArtificial | DIFlagObjectPointer)
anatofuz
parents:
diff changeset
201 // CHECK-2-DAG: !DILocalVariable(name: "__context", {{.*}}, flags: DIFlagArtificial)
anatofuz
parents:
diff changeset
202 // CHECK-3-DAG: !DILocalVariable(name: "this", {{.*}}, flags: DIFlagArtificial | DIFlagObjectPointer)
anatofuz
parents:
diff changeset
203 // CHECK-3-DAG: !DILocalVariable(name: "__context", {{.*}}, flags: DIFlagArtificial)
anatofuz
parents:
diff changeset
204 // CHECK-4-DAG: !DILocalVariable(name: "this", {{.*}}, flags: DIFlagArtificial | DIFlagObjectPointer)
anatofuz
parents:
diff changeset
205 // CHECK-4-DAG: !DILocalVariable(name: "__context", {{.*}}, flags: DIFlagArtificial)
anatofuz
parents:
diff changeset
206 // CHECK-5-DAG: !DILocalVariable(name: "this", {{.*}}, flags: DIFlagArtificial | DIFlagObjectPointer)
anatofuz
parents:
diff changeset
207 // CHECK-5-DAG: !DILocalVariable(name: "__context", {{.*}}, flags: DIFlagArtificial)
anatofuz
parents:
diff changeset
208 // CHECK-6-DAG: !DILocalVariable(name: "this", {{.*}}, flags: DIFlagArtificial | DIFlagObjectPointer)
anatofuz
parents:
diff changeset
209 // CHECK-6-DAG: !DILocalVariable(name: "__context", {{.*}}, flags: DIFlagArtificial)
anatofuz
parents:
diff changeset
210 // CHECK-7-DAG: !DILocalVariable(name: "this", {{.*}}, flags: DIFlagArtificial | DIFlagObjectPointer)
anatofuz
parents:
diff changeset
211 // CHECK-7-DAG: !DILocalVariable(name: "__context", {{.*}}, flags: DIFlagArtificial)