1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
4 template <typename T
> T
* g() {
29 // CHECK-LABEL: define{{.*}} void @_Z11if_destructi(
30 void if_destruct(int z
) {
31 // Verify that the condition variable is destroyed at the end of the
33 // CHECK: call void @_ZN1XC1Ev
34 // CHECK: call noundef zeroext i1 @_ZN1XcvbEv
36 // CHECK: store i32 18
39 // CHECK: call void @_ZN1XD1Ev
40 // CHECK: store i32 17
43 // CHECK: call void @_ZN1XC1Ev
47 // CHECK: call void @_ZN1YC1Ev
48 // CHECK: call void @_ZN1YD1Ev
50 // CHECK: call void @_ZN1XD1Ev
52 // CHECK: call void @_Z4getXv
53 // CHECK: call noundef zeroext i1 @_ZN1XcvbEv
54 // CHECK: call void @_ZN1XD1Ev
61 struct ConvertibleToInt
{
67 ConvertibleToInt
getConvToInt();
69 void switch_destruct(int z
) {
70 // CHECK: call void @_ZN16ConvertibleToIntC1Ev
71 switch (ConvertibleToInt conv
= ConvertibleToInt()) {
76 // CHECK: store i32 19
80 // CHECK: call void @_ZN16ConvertibleToIntD1Ev
81 // CHECK: store i32 20
84 // CHECK: call void @_Z12getConvToIntv
85 // CHECK: call noundef i32 @_ZN16ConvertibleToIntcviEv
86 // CHECK: call void @_ZN16ConvertibleToIntD1Ev
87 switch(getConvToInt()) {
91 // CHECK: store i32 27
98 // CHECK-LABEL: define{{.*}} void @_Z14while_destructi
99 void while_destruct(int z
) {
100 // CHECK: [[Z:%.*]] = alloca i32
101 // CHECK: [[CLEANUPDEST:%.*]] = alloca i32
103 // CHECK: call void @_ZN1XC1Ev
104 // CHECK-NEXT: [[COND:%.*]] = call noundef zeroext i1 @_ZN1XcvbEv
105 // CHECK-NEXT: br i1 [[COND]]
107 // Loop-exit staging block.
108 // CHECK: store i32 3, i32* [[CLEANUPDEST]]
112 // CHECK: store i32 21, i32* [[Z]]
113 // CHECK: store i32 0, i32* [[CLEANUPDEST]]
118 // CHECK: call void @_ZN1XD1Ev
119 // CHECK-NEXT: [[DEST:%.*]] = load i32, i32* [[CLEANUPDEST]]
120 // CHECK-NEXT: switch i32 [[DEST]]
123 // CHECK: store i32 22, i32* [[Z]]
126 // CHECK: call void @_Z4getXv
127 // CHECK-NEXT: call noundef zeroext i1 @_ZN1XcvbEv
128 // CHECK-NEXT: call void @_ZN1XD1Ev
132 // CHECK: store i32 25, i32* [[Z]]
138 // CHECK-LABEL: define{{.*}} void @_Z12for_destructi(
139 void for_destruct(int z
) {
140 // CHECK: [[Z:%.*]] = alloca i32
141 // CHECK: [[CLEANUPDEST:%.*]] = alloca i32
142 // CHECK: [[I:%.*]] = alloca i32
143 // CHECK: call void @_ZN1YC1Ev
147 for(Y y
= Y(); X x
= X(); ++z
) {
148 // %for.cond: The loop condition.
149 // CHECK: call void @_ZN1XC1Ev
150 // CHECK-NEXT: [[COND:%.*]] = call noundef zeroext i1 @_ZN1XcvbEv(
151 // CHECK-NEXT: br i1 [[COND]]
152 // -> %for.body, %for.cond.cleanup
154 // %for.cond.cleanup: Exit cleanup staging.
155 // CHECK: store i32 2, i32* [[CLEANUPDEST]]
160 // CHECK: store i32 23, i32* [[Z]]
166 // CHECK: [[TMP:%.*]] = load i32, i32* [[Z]]
167 // CHECK-NEXT: [[INC:%.*]] = add nsw i32 [[TMP]], 1
168 // CHECK-NEXT: store i32 [[INC]], i32* [[Z]]
169 // CHECK-NEXT: store i32 0, i32* [[CLEANUPDEST]]
173 // %cleanup: Destroys X.
174 // CHECK: call void @_ZN1XD1Ev
175 // CHECK-NEXT: [[YDESTTMP:%.*]] = load i32, i32* [[CLEANUPDEST]]
176 // CHECK-NEXT: switch i32 [[YDESTTMP]]
177 // 0 -> %cleanup.cont, default -> %cleanup1
179 // %cleanup.cont: (eliminable)
183 // %cleanup1: Destroys Y.
184 // CHECK: call void @_ZN1YD1Ev(
190 // CHECK: store i32 24
193 // CHECK-NEXT: store i32 0, i32* [[I]]
198 // CHECK: call void @_Z4getXv
199 // CHECK-NEXT: call noundef zeroext i1 @_ZN1XcvbEv
200 // CHECK-NEXT: call void @_ZN1XD1Ev
202 // -> %for.body10, %for.end16
209 // CHECK: call void @_Z4getXv
210 // CHECK-NEXT: load i32, i32* [[I]]
213 // CHECK-NEXT: call void @_ZN1XD1Ev
217 for(; getX(); getX(), ++i
) { }
220 // CHECK: store i32 26
223 // CHECK-NEXT: ret void
226 void do_destruct(int z
) {
227 // CHECK-LABEL: define{{.*}} void @_Z11do_destruct
229 // CHECK: store i32 77
231 // CHECK: call void @_Z4getXv
232 // CHECK: call noundef zeroext i1 @_ZN1XcvbEv
233 // CHECK: call void @_ZN1XD1Ev
236 // CHECK: store i32 99
244 int instantiated(T x
) {
247 // CHECK: call void @_ZN1XC1ERKS_
248 // CHECK: call noundef i32 @_Z1f1X
249 // CHECK: call void @_ZN1XD1Ev
251 // CHECK: store i32 2
253 // CHECK: store i32 3
254 if (f(x
)) { result
= 2; } else { result
= 3; }
256 // CHECK: call void @_ZN1XC1ERKS_
257 // CHECK: call noundef i32 @_Z1f1X
258 // CHECK: call void @_ZN1XD1Ev
260 // CHECK: store i32 4
262 while (f(x
)) { result
= 4; }
264 // CHECK: call void @_ZN1XC1ERKS_
265 // CHECK: call noundef i32 @_Z1f1X
266 // CHECK: call void @_ZN1XD1Ev
268 // CHECK: store i32 6
270 // CHECK: call void @_ZN1XC1ERKS_
271 // CHECK: call noundef i32 @_Z1f1X
272 // CHECK: store i32 5
273 // CHECK: call void @_ZN1XD1Ev
275 for (; f(x
); f(x
), result
= 5) {
279 // CHECK: call void @_ZN1XC1ERKS_
280 // CHECK: call noundef i32 @_Z1f1X
281 // CHECK: call void @_ZN1XD1Ev
283 // CHECK: store i32 7
284 // CHECK: store i32 8
294 // CHECK: store i32 9
296 // CHECK: call void @_ZN1XC1ERKS_
297 // CHECK: call noundef i32 @_Z1f1X
298 // CHECK: call void @_ZN1XD1Ev
304 // CHECK: store i32 10
305 // CHECK: call void @_ZN1XC1ERKS_
306 // CHECK: call noundef zeroext i1 @_ZN1XcvbEv
307 // CHECK: call void @_ZN1XD1Ev
317 template int instantiated(X
);