1 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -analyze -analyzer-checker=debug.DumpCFG -analyzer-config cfg-lifetime=true %s > %t 2>&1
2 // RUN: FileCheck --input-file=%t %s
4 // FIXME Most of the cases in this file test only with the objects of type `A`,
5 // that has a non-trivial destructor. The types with a trivial destructor
6 // ends their lifetime when the underlying memory is released, i.e. they
7 // are destroyed last, after all objects with non-trivial destructors.
8 // Consequently, they are handled differently in code, and we should make
9 // sure that test cover also trivially destructible types.
14 // CHECK: [B2 (ENTRY)]
15 // CHECK-NEXT: Succs (1): B1
17 // CHECK-NEXT: 1: true
19 // CHECK-NEXT: 3: [B1.2] = [B1.1]
20 // CHECK-NEXT: Preds (1): B2
21 // CHECK-NEXT: Succs (1): B0
23 // CHECK-NEXT: Preds (1): B1
27 // CHECK: [B3 (ENTRY)]
28 // CHECK-NEXT: Succs (1): B2
31 // CHECK-NEXT: 2: this
32 // CHECK-NEXT: 3: [B1.2]->p
33 // CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, LValueToRValue, int *)
34 // CHECK-NEXT: 5: *[B1.4]
35 // CHECK-NEXT: 6: [B1.5] = [B1.1]
36 // CHECK-NEXT: Preds (1): B2
37 // CHECK-NEXT: Succs (1): B0
39 // CHECK-NEXT: 1: this
40 // CHECK-NEXT: 2: [B2.1]->p
41 // CHECK-NEXT: 3: [B2.2] (ImplicitCastExpr, LValueToRValue, int *)
42 // CHECK-NEXT: 4: [B2.3] (ImplicitCastExpr, PointerToBoolean, _Bool)
43 // CHECK-NEXT: T: if [B2.4]
44 // CHECK-NEXT: Preds (1): B3
45 // CHECK-NEXT: Succs (2): B1 B0
47 // CHECK-NEXT: Preds (2): B1 B2
52 // CHECK: [B2 (ENTRY)]
53 // CHECK-NEXT: Succs (1): B1
56 // CHECK-NEXT: 2: return [B1.1];
57 // CHECK-NEXT: Preds (1): B2
58 // CHECK-NEXT: Succs (1): B0
60 // CHECK-NEXT: Preds (1): B1
61 operator int() const { return 1; }
65 // CHECK: [B2 (ENTRY)]
66 // CHECK-NEXT: Succs (1): B1
68 // CHECK-NEXT: 1: (CXXConstructExpr, [B1.2], A)
69 // CHECK-NEXT: 2: A a;
71 // CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, NoOp, const A)
72 // CHECK-NEXT: 5: const A &b = a;
73 // CHECK-NEXT: 6: A() (CXXConstructExpr, [B1.9], A)
74 // CHECK-NEXT: 7: [B1.6] (BindTemporary)
75 // CHECK-NEXT: 8: [B1.7] (ImplicitCastExpr, NoOp, const A)
76 // CHECK-NEXT: 9: [B1.8]
77 // CHECK-NEXT: 10: const A &c = A();
78 // CHECK-NEXT: 11: [B1.10].~A() (Implicit destructor)
79 // CHECK-NEXT: 12: [B1.10] (Lifetime ends)
80 // CHECK-NEXT: 13: [B1.2].~A() (Implicit destructor)
81 // CHECK-NEXT: 14: [B1.2] (Lifetime ends)
82 // CHECK-NEXT: 15: [B1.5] (Lifetime ends)
83 // CHECK-NEXT: Preds (1): B2
84 // CHECK-NEXT: Succs (1): B0
86 // CHECK-NEXT: Preds (1): B1
87 void test_const_ref() {
93 // CHECK: [B2 (ENTRY)]
94 // CHECK-NEXT: Succs (1): B1
96 // CHECK-NEXT: 1: (CXXConstructExpr, [B1.2], A[2])
97 // CHECK-NEXT: 2: A a[2];
98 // CHECK-NEXT: 3: (CXXConstructExpr, [B1.4], A[0])
99 // CHECK-NEXT: 4: A b[0];
100 // CHECK-NEXT: 5: [B1.2].~A[2]() (Implicit destructor)
101 // lifetime of a ends when its destructors are run
102 // CHECK-NEXT: 6: [B1.2] (Lifetime ends)
103 // lifetime of b ends when its storage duration ends
104 // CHECK-NEXT: 7: [B1.4] (Lifetime ends)
105 // CHECK-NEXT: Preds (1): B2
106 // CHECK-NEXT: Succs (1): B0
107 // CHECK: [B0 (EXIT)]
108 // CHECK-NEXT: Preds (1): B1
114 // CHECK: [B2 (ENTRY)]
115 // CHECK-NEXT: Succs (1): B1
117 // CHECK-NEXT: 1: (CXXConstructExpr, [B1.2], A)
118 // CHECK-NEXT: 2: A a;
119 // CHECK-NEXT: 3: (CXXConstructExpr, [B1.4], A)
120 // CHECK-NEXT: 4: A c;
121 // CHECK-NEXT: 5: (CXXConstructExpr, [B1.6], A)
122 // CHECK-NEXT: 6: A d;
123 // CHECK-NEXT: 7: [B1.6].~A() (Implicit destructor)
124 // CHECK-NEXT: 8: [B1.6] (Lifetime ends)
125 // CHECK-NEXT: 9: [B1.4].~A() (Implicit destructor)
126 // CHECK-NEXT: 10: [B1.4] (Lifetime ends)
127 // CHECK-NEXT: 11: (CXXConstructExpr, [B1.12], A)
128 // CHECK-NEXT: 12: A b;
129 // CHECK-NEXT: 13: [B1.12].~A() (Implicit destructor)
130 // CHECK-NEXT: 14: [B1.12] (Lifetime ends)
131 // CHECK-NEXT: 15: [B1.2].~A() (Implicit destructor)
132 // CHECK-NEXT: 16: [B1.2] (Lifetime ends)
133 // CHECK-NEXT: Preds (1): B2
134 // CHECK-NEXT: Succs (1): B0
135 // CHECK: [B0 (EXIT)]
136 // CHECK-NEXT: Preds (1): B1
146 // CHECK: [B4 (ENTRY)]
147 // CHECK-NEXT: Succs (1): B3
149 // CHECK-NEXT: 1: (CXXConstructExpr, [B1.2], A)
150 // CHECK-NEXT: 2: A c;
151 // CHECK-NEXT: 3: [B1.2].~A() (Implicit destructor)
152 // CHECK-NEXT: 4: [B1.2] (Lifetime ends)
153 // CHECK-NEXT: 5: [B3.4].~A() (Implicit destructor)
154 // CHECK-NEXT: 6: [B3.4] (Lifetime ends)
155 // CHECK-NEXT: 7: [B3.2].~A() (Implicit destructor)
156 // CHECK-NEXT: 8: [B3.2] (Lifetime ends)
157 // CHECK-NEXT: Preds (1): B3
158 // CHECK-NEXT: Succs (1): B0
160 // CHECK-NEXT: 1: return;
161 // CHECK-NEXT: 2: [B3.4].~A() (Implicit destructor)
162 // CHECK-NEXT: 3: [B3.4] (Lifetime ends)
163 // CHECK-NEXT: 4: [B3.2].~A() (Implicit destructor)
164 // CHECK-NEXT: 5: [B3.2] (Lifetime ends)
165 // CHECK-NEXT: Preds (1): B3
166 // CHECK-NEXT: Succs (1): B0
168 // CHECK-NEXT: 1: (CXXConstructExpr, [B3.2], A)
169 // CHECK-NEXT: 2: A a;
170 // CHECK-NEXT: 3: (CXXConstructExpr, [B3.4], A)
171 // CHECK-NEXT: 4: A b;
173 // CHECK-NEXT: 6: [B3.5] (ImplicitCastExpr, LValueToRValue, _Bool)
174 // CHECK-NEXT: T: if [B3.6]
175 // CHECK-NEXT: Preds (1): B4
176 // CHECK-NEXT: Succs (2): B2 B1
177 // CHECK: [B0 (EXIT)]
178 // CHECK-NEXT: Preds (2): B1 B2
187 // CHECK: [B5 (ENTRY)]
188 // CHECK-NEXT: Succs (1): B4
190 // CHECK-NEXT: 1: [B4.6].~A() (Implicit destructor)
191 // CHECK-NEXT: 2: [B4.6] (Lifetime ends)
192 // CHECK-NEXT: 3: [B4.2].~A() (Implicit destructor)
193 // CHECK-NEXT: 4: [B4.2] (Lifetime ends)
194 // CHECK-NEXT: Preds (2): B2 B3
195 // CHECK-NEXT: Succs (1): B0
197 // CHECK-NEXT: 1: (CXXConstructExpr, [B2.2], A)
198 // CHECK-NEXT: 2: A c;
199 // CHECK-NEXT: 3: [B2.2].~A() (Implicit destructor)
200 // CHECK-NEXT: 4: [B2.2] (Lifetime ends)
201 // CHECK-NEXT: Preds (1): B4
202 // CHECK-NEXT: Succs (1): B1
204 // CHECK-NEXT: 1: (CXXConstructExpr, [B3.2], A)
205 // CHECK-NEXT: 2: A c;
206 // CHECK-NEXT: 3: [B3.2].~A() (Implicit destructor)
207 // CHECK-NEXT: 4: [B3.2] (Lifetime ends)
208 // CHECK-NEXT: Preds (1): B4
209 // CHECK-NEXT: Succs (1): B1
211 // CHECK-NEXT: 1: (CXXConstructExpr, [B4.2], A)
212 // CHECK-NEXT: 2: A a;
214 // CHECK-NEXT: 4: [B4.3] (ImplicitCastExpr, NoOp, const A)
215 // CHECK-NEXT: 5: [B4.4] (CXXConstructExpr, [B4.6], A)
216 // CHECK-NEXT: 6: A b = a;
218 // CHECK-NEXT: 8: [B4.7] (ImplicitCastExpr, NoOp, const class A)
219 // CHECK-NEXT: 9: [B4.8].operator int
220 // CHECK-NEXT: 10: [B4.8]
221 // CHECK-NEXT: 11: [B4.10] (ImplicitCastExpr, UserDefinedConversion, int)
222 // CHECK-NEXT: 12: [B4.11] (ImplicitCastExpr, IntegralToBoolean, _Bool)
223 // CHECK-NEXT: T: if [B4.12]
224 // CHECK-NEXT: Preds (1): B5
225 // CHECK-NEXT: Succs (2): B3 B2
226 // CHECK: [B0 (EXIT)]
227 // CHECK-NEXT: Preds (1): B1
228 void test_if_implicit_scope() {
236 // CHECK: [B9 (ENTRY)]
237 // CHECK-NEXT: Succs (1): B8
239 // CHECK-NEXT: 1: [B8.6].~A() (Implicit destructor)
240 // CHECK-NEXT: 2: [B8.6] (Lifetime ends)
241 // CHECK-NEXT: 3: (CXXConstructExpr, [B1.4], A)
242 // CHECK-NEXT: 4: A e;
243 // CHECK-NEXT: 5: [B1.4].~A() (Implicit destructor)
244 // CHECK-NEXT: 6: [B1.4] (Lifetime ends)
245 // CHECK-NEXT: 7: [B8.2].~A() (Implicit destructor)
246 // CHECK-NEXT: 8: [B8.2] (Lifetime ends)
247 // CHECK-NEXT: Preds (2): B2 B5
248 // CHECK-NEXT: Succs (1): B0
250 // CHECK-NEXT: 1: (CXXConstructExpr, [B2.2], A)
251 // CHECK-NEXT: 2: A d;
252 // CHECK-NEXT: 3: [B2.2].~A() (Implicit destructor)
253 // CHECK-NEXT: 4: [B2.2] (Lifetime ends)
254 // CHECK-NEXT: 5: [B4.2].~A() (Implicit destructor)
255 // CHECK-NEXT: 6: [B4.2] (Lifetime ends)
256 // CHECK-NEXT: Preds (1): B4
257 // CHECK-NEXT: Succs (1): B1
259 // CHECK-NEXT: 1: return;
260 // CHECK-NEXT: 2: [B4.2].~A() (Implicit destructor)
261 // CHECK-NEXT: 3: [B4.2] (Lifetime ends)
262 // CHECK-NEXT: 4: [B8.6].~A() (Implicit destructor)
263 // CHECK-NEXT: 5: [B8.6] (Lifetime ends)
264 // CHECK-NEXT: 6: [B8.2].~A() (Implicit destructor)
265 // CHECK-NEXT: 7: [B8.2] (Lifetime ends)
266 // CHECK-NEXT: Preds (1): B4
267 // CHECK-NEXT: Succs (1): B0
269 // CHECK-NEXT: 1: (CXXConstructExpr, [B4.2], A)
270 // CHECK-NEXT: 2: A c;
272 // CHECK-NEXT: 4: [B4.3] (ImplicitCastExpr, LValueToRValue, _Bool)
273 // CHECK-NEXT: T: if [B4.4]
274 // CHECK-NEXT: Preds (1): B8
275 // CHECK-NEXT: Succs (2): B3 B2
277 // CHECK-NEXT: 1: (CXXConstructExpr, [B5.2], A)
278 // CHECK-NEXT: 2: A d;
279 // CHECK-NEXT: 3: [B5.2].~A() (Implicit destructor)
280 // CHECK-NEXT: 4: [B5.2] (Lifetime ends)
281 // CHECK-NEXT: 5: [B7.2].~A() (Implicit destructor)
282 // CHECK-NEXT: 6: [B7.2] (Lifetime ends)
283 // CHECK-NEXT: Preds (1): B7
284 // CHECK-NEXT: Succs (1): B1
286 // CHECK-NEXT: 1: return;
287 // CHECK-NEXT: 2: [B7.2].~A() (Implicit destructor)
288 // CHECK-NEXT: 3: [B7.2] (Lifetime ends)
289 // CHECK-NEXT: 4: [B8.6].~A() (Implicit destructor)
290 // CHECK-NEXT: 5: [B8.6] (Lifetime ends)
291 // CHECK-NEXT: 6: [B8.2].~A() (Implicit destructor)
292 // CHECK-NEXT: 7: [B8.2] (Lifetime ends)
293 // CHECK-NEXT: Preds (1): B7
294 // CHECK-NEXT: Succs (1): B0
296 // CHECK-NEXT: 1: (CXXConstructExpr, [B7.2], A)
297 // CHECK-NEXT: 2: A c;
299 // CHECK-NEXT: 4: [B7.3] (ImplicitCastExpr, LValueToRValue, _Bool)
300 // CHECK-NEXT: T: if [B7.4]
301 // CHECK-NEXT: Preds (1): B8
302 // CHECK-NEXT: Succs (2): B6 B5
304 // CHECK-NEXT: 1: (CXXConstructExpr, [B8.2], A)
305 // CHECK-NEXT: 2: A a;
307 // CHECK-NEXT: 4: [B8.3] (ImplicitCastExpr, NoOp, const A)
308 // CHECK-NEXT: 5: [B8.4] (CXXConstructExpr, [B8.6], A)
309 // CHECK-NEXT: 6: A b = a;
311 // CHECK-NEXT: 8: [B8.7] (ImplicitCastExpr, NoOp, const class A)
312 // CHECK-NEXT: 9: [B8.8].operator int
313 // CHECK-NEXT: 10: [B8.8]
314 // CHECK-NEXT: 11: [B8.10] (ImplicitCastExpr, UserDefinedConversion, int)
315 // CHECK-NEXT: 12: [B8.11] (ImplicitCastExpr, IntegralToBoolean, _Bool)
316 // CHECK-NEXT: T: if [B8.12]
317 // CHECK-NEXT: Preds (1): B9
318 // CHECK-NEXT: Succs (2): B7 B4
319 // CHECK: [B0 (EXIT)]
320 // CHECK-NEXT: Preds (3): B1 B3 B6
321 void test_if_jumps() {
337 // CHECK: [B6 (ENTRY)]
338 // CHECK-NEXT: Succs (1): B5
340 // CHECK-NEXT: 1: [B4.4].~A() (Implicit destructor)
341 // CHECK-NEXT: 2: [B4.4] (Lifetime ends)
342 // CHECK-NEXT: 3: [B5.2].~A() (Implicit destructor)
343 // CHECK-NEXT: 4: [B5.2] (Lifetime ends)
344 // CHECK-NEXT: Preds (1): B4
345 // CHECK-NEXT: Succs (1): B0
347 // CHECK-NEXT: Preds (1): B3
348 // CHECK-NEXT: Succs (1): B4
350 // CHECK-NEXT: 1: (CXXConstructExpr, [B3.2], A)
351 // CHECK-NEXT: 2: A c;
352 // CHECK-NEXT: 3: [B3.2].~A() (Implicit destructor)
353 // CHECK-NEXT: 4: [B3.2] (Lifetime ends)
354 // CHECK-NEXT: 5: [B4.4].~A() (Implicit destructor)
355 // CHECK-NEXT: 6: [B4.4] (Lifetime ends)
356 // CHECK-NEXT: Preds (1): B4
357 // CHECK-NEXT: Succs (1): B2
360 // CHECK-NEXT: 2: [B4.1] (ImplicitCastExpr, NoOp, const A)
361 // CHECK-NEXT: 3: [B4.2] (CXXConstructExpr, [B4.4], A)
362 // CHECK-NEXT: 4: A b = a;
364 // CHECK-NEXT: 6: [B4.5] (ImplicitCastExpr, NoOp, const class A)
365 // CHECK-NEXT: 7: [B4.6].operator int
366 // CHECK-NEXT: 8: [B4.6]
367 // CHECK-NEXT: 9: [B4.8] (ImplicitCastExpr, UserDefinedConversion, int)
368 // CHECK-NEXT: 10: [B4.9] (ImplicitCastExpr, IntegralToBoolean, _Bool)
369 // CHECK-NEXT: T: while [B4.10]
370 // CHECK-NEXT: Preds (2): B2 B5
371 // CHECK-NEXT: Succs (2): B3 B1
373 // CHECK-NEXT: 1: (CXXConstructExpr, [B5.2], A)
374 // CHECK-NEXT: 2: A a;
375 // CHECK-NEXT: Preds (1): B6
376 // CHECK-NEXT: Succs (1): B4
377 // CHECK: [B0 (EXIT)]
378 // CHECK-NEXT: Preds (1): B1
379 void test_while_implicit_scope() {
385 // CHECK: [B12 (ENTRY)]
386 // CHECK-NEXT: Succs (1): B11
388 // CHECK-NEXT: 1: [B10.4].~A() (Implicit destructor)
389 // CHECK-NEXT: 2: [B10.4] (Lifetime ends)
390 // CHECK-NEXT: 3: (CXXConstructExpr, [B1.4], A)
391 // CHECK-NEXT: 4: A e;
392 // CHECK-NEXT: 5: [B1.4].~A() (Implicit destructor)
393 // CHECK-NEXT: 6: [B1.4] (Lifetime ends)
394 // CHECK-NEXT: 7: [B11.2].~A() (Implicit destructor)
395 // CHECK-NEXT: 8: [B11.2] (Lifetime ends)
396 // CHECK-NEXT: Preds (2): B8 B10
397 // CHECK-NEXT: Succs (1): B0
399 // CHECK-NEXT: Preds (2): B3 B6
400 // CHECK-NEXT: Succs (1): B10
402 // CHECK-NEXT: 1: (CXXConstructExpr, [B3.2], A)
403 // CHECK-NEXT: 2: A d;
404 // CHECK-NEXT: 3: [B3.2].~A() (Implicit destructor)
405 // CHECK-NEXT: 4: [B3.2] (Lifetime ends)
406 // CHECK-NEXT: 5: [B9.2].~A() (Implicit destructor)
407 // CHECK-NEXT: 6: [B9.2] (Lifetime ends)
408 // CHECK-NEXT: 7: [B10.4].~A() (Implicit destructor)
409 // CHECK-NEXT: 8: [B10.4] (Lifetime ends)
410 // CHECK-NEXT: Preds (1): B5
411 // CHECK-NEXT: Succs (1): B2
413 // CHECK-NEXT: 1: return;
414 // CHECK-NEXT: 2: [B9.2].~A() (Implicit destructor)
415 // CHECK-NEXT: 3: [B9.2] (Lifetime ends)
416 // CHECK-NEXT: 4: [B10.4].~A() (Implicit destructor)
417 // CHECK-NEXT: 5: [B10.4] (Lifetime ends)
418 // CHECK-NEXT: 6: [B11.2].~A() (Implicit destructor)
419 // CHECK-NEXT: 7: [B11.2] (Lifetime ends)
420 // CHECK-NEXT: Preds (1): B5
421 // CHECK-NEXT: Succs (1): B0
424 // CHECK-NEXT: 2: [B5.1] (ImplicitCastExpr, LValueToRValue, _Bool)
425 // CHECK-NEXT: T: if [B5.2]
426 // CHECK-NEXT: Preds (1): B7
427 // CHECK-NEXT: Succs (2): B4 B3
429 // CHECK-NEXT: 1: [B9.2].~A() (Implicit destructor)
430 // CHECK-NEXT: 2: [B9.2] (Lifetime ends)
431 // CHECK-NEXT: 3: [B10.4].~A() (Implicit destructor)
432 // CHECK-NEXT: 4: [B10.4] (Lifetime ends)
433 // CHECK-NEXT: T: continue;
434 // CHECK-NEXT: Preds (1): B7
435 // CHECK-NEXT: Succs (1): B2
438 // CHECK-NEXT: 2: [B7.1] (ImplicitCastExpr, LValueToRValue, _Bool)
439 // CHECK-NEXT: T: if [B7.2]
440 // CHECK-NEXT: Preds (1): B9
441 // CHECK-NEXT: Succs (2): B6 B5
443 // CHECK-NEXT: 1: [B9.2].~A() (Implicit destructor)
444 // CHECK-NEXT: 2: [B9.2] (Lifetime ends)
445 // CHECK-NEXT: T: break;
446 // CHECK-NEXT: Preds (1): B9
447 // CHECK-NEXT: Succs (1): B1
449 // CHECK-NEXT: 1: (CXXConstructExpr, [B9.2], A)
450 // CHECK-NEXT: 2: A c;
452 // CHECK-NEXT: 4: [B9.3] (ImplicitCastExpr, LValueToRValue, _Bool)
453 // CHECK-NEXT: T: if [B9.4]
454 // CHECK-NEXT: Preds (1): B10
455 // CHECK-NEXT: Succs (2): B8 B7
458 // CHECK-NEXT: 2: [B10.1] (ImplicitCastExpr, NoOp, const A)
459 // CHECK-NEXT: 3: [B10.2] (CXXConstructExpr, [B10.4], A)
460 // CHECK-NEXT: 4: A b = a;
462 // CHECK-NEXT: 6: [B10.5] (ImplicitCastExpr, NoOp, const class A)
463 // CHECK-NEXT: 7: [B10.6].operator int
464 // CHECK-NEXT: 8: [B10.6]
465 // CHECK-NEXT: 9: [B10.8] (ImplicitCastExpr, UserDefinedConversion, int)
466 // CHECK-NEXT: 10: [B10.9] (ImplicitCastExpr, IntegralToBoolean, _Bool)
467 // CHECK-NEXT: T: while [B10.10]
468 // CHECK-NEXT: Preds (2): B2 B11
469 // CHECK-NEXT: Succs (2): B9 B1
471 // CHECK-NEXT: 1: (CXXConstructExpr, [B11.2], A)
472 // CHECK-NEXT: 2: A a;
473 // CHECK-NEXT: Preds (1): B12
474 // CHECK-NEXT: Succs (1): B10
475 // CHECK: [B0 (EXIT)]
476 // CHECK-NEXT: Preds (2): B1 B4
477 void test_while_jumps() {
492 // CHECK: [B12 (ENTRY)]
493 // CHECK-NEXT: Succs (1): B11
495 // CHECK-NEXT: 1: (CXXConstructExpr, [B1.2], A)
496 // CHECK-NEXT: 2: A d;
497 // CHECK-NEXT: 3: [B1.2].~A() (Implicit destructor)
498 // CHECK-NEXT: 4: [B1.2] (Lifetime ends)
499 // CHECK-NEXT: 5: [B11.2].~A() (Implicit destructor)
500 // CHECK-NEXT: 6: [B11.2] (Lifetime ends)
501 // CHECK-NEXT: Preds (2): B8 B2
502 // CHECK-NEXT: Succs (1): B0
505 // CHECK-NEXT: 2: [B2.1] (ImplicitCastExpr, LValueToRValue, _Bool)
506 // CHECK-NEXT: T: do ... while [B2.2]
507 // CHECK-NEXT: Preds (2): B3 B6
508 // CHECK-NEXT: Succs (2): B10 B1
510 // CHECK-NEXT: 1: (CXXConstructExpr, [B3.2], A)
511 // CHECK-NEXT: 2: A c;
512 // CHECK-NEXT: 3: [B3.2].~A() (Implicit destructor)
513 // CHECK-NEXT: 4: [B3.2] (Lifetime ends)
514 // CHECK-NEXT: 5: [B9.2].~A() (Implicit destructor)
515 // CHECK-NEXT: 6: [B9.2] (Lifetime ends)
516 // CHECK-NEXT: Preds (1): B5
517 // CHECK-NEXT: Succs (1): B2
519 // CHECK-NEXT: 1: return;
520 // CHECK-NEXT: 2: [B9.2].~A() (Implicit destructor)
521 // CHECK-NEXT: 3: [B9.2] (Lifetime ends)
522 // CHECK-NEXT: 4: [B11.2].~A() (Implicit destructor)
523 // CHECK-NEXT: 5: [B11.2] (Lifetime ends)
524 // CHECK-NEXT: Preds (1): B5
525 // CHECK-NEXT: Succs (1): B0
528 // CHECK-NEXT: 2: [B5.1] (ImplicitCastExpr, LValueToRValue, _Bool)
529 // CHECK-NEXT: T: if [B5.2]
530 // CHECK-NEXT: Preds (1): B7
531 // CHECK-NEXT: Succs (2): B4 B3
533 // CHECK-NEXT: 1: [B9.2].~A() (Implicit destructor)
534 // CHECK-NEXT: 2: [B9.2] (Lifetime ends)
535 // CHECK-NEXT: T: continue;
536 // CHECK-NEXT: Preds (1): B7
537 // CHECK-NEXT: Succs (1): B2
540 // CHECK-NEXT: 2: [B7.1] (ImplicitCastExpr, LValueToRValue, _Bool)
541 // CHECK-NEXT: T: if [B7.2]
542 // CHECK-NEXT: Preds (1): B9
543 // CHECK-NEXT: Succs (2): B6 B5
545 // CHECK-NEXT: 1: [B9.2].~A() (Implicit destructor)
546 // CHECK-NEXT: 2: [B9.2] (Lifetime ends)
547 // CHECK-NEXT: T: break;
548 // CHECK-NEXT: Preds (1): B9
549 // CHECK-NEXT: Succs (1): B1
551 // CHECK-NEXT: 1: (CXXConstructExpr, [B9.2], A)
552 // CHECK-NEXT: 2: A b;
554 // CHECK-NEXT: 4: [B9.3] (ImplicitCastExpr, LValueToRValue, _Bool)
555 // CHECK-NEXT: T: if [B9.4]
556 // CHECK-NEXT: Preds (2): B10 B11
557 // CHECK-NEXT: Succs (2): B8 B7
559 // CHECK-NEXT: Preds (1): B2
560 // CHECK-NEXT: Succs (1): B9
562 // CHECK-NEXT: 1: (CXXConstructExpr, [B11.2], A)
563 // CHECK-NEXT: 2: A a;
564 // CHECK-NEXT: Preds (1): B12
565 // CHECK-NEXT: Succs (1): B9
566 // CHECK: [B0 (EXIT)]
567 // CHECK-NEXT: Preds (2): B1 B4
568 void test_do_jumps() {
583 // CHECK: [B6 (ENTRY)]
584 // CHECK-NEXT: Succs (1): B5
586 // CHECK-NEXT: 1: [B4.4].~A() (Implicit destructor)
587 // CHECK-NEXT: 2: [B4.4] (Lifetime ends)
588 // CHECK-NEXT: 3: [B5.2].~A() (Implicit destructor)
589 // CHECK-NEXT: 4: [B5.2] (Lifetime ends)
590 // CHECK-NEXT: Preds (1): B4
591 // CHECK-NEXT: Succs (1): B0
594 // CHECK-NEXT: 2: [B2.1].p
595 // CHECK-NEXT: 3: [B4.4].~A() (Implicit destructor)
596 // CHECK-NEXT: 4: [B4.4] (Lifetime ends)
597 // CHECK-NEXT: Preds (1): B3
598 // CHECK-NEXT: Succs (1): B4
600 // CHECK-NEXT: 1: (CXXConstructExpr, [B3.2], A)
601 // CHECK-NEXT: 2: A c;
602 // CHECK-NEXT: 3: [B3.2].~A() (Implicit destructor)
603 // CHECK-NEXT: 4: [B3.2] (Lifetime ends)
604 // CHECK-NEXT: Preds (1): B4
605 // CHECK-NEXT: Succs (1): B2
608 // CHECK-NEXT: 2: [B4.1] (ImplicitCastExpr, NoOp, const A)
609 // CHECK-NEXT: 3: [B4.2] (CXXConstructExpr, [B4.4], A)
610 // CHECK-NEXT: 4: A b = a;
612 // CHECK-NEXT: 6: [B4.5] (ImplicitCastExpr, NoOp, const class A)
613 // CHECK-NEXT: 7: [B4.6].operator int
614 // CHECK-NEXT: 8: [B4.6]
615 // CHECK-NEXT: 9: [B4.8] (ImplicitCastExpr, UserDefinedConversion, int)
616 // CHECK-NEXT: 10: [B4.9] (ImplicitCastExpr, IntegralToBoolean, _Bool)
617 // CHECK-NEXT: T: for (...; [B4.10]; ...)
618 // CHECK-NEXT: Preds (2): B2 B5
619 // CHECK-NEXT: Succs (2): B3 B1
621 // CHECK-NEXT: 1: (CXXConstructExpr, [B5.2], A)
622 // CHECK-NEXT: 2: A a;
623 // CHECK-NEXT: Preds (1): B6
624 // CHECK-NEXT: Succs (1): B4
625 // CHECK: [B0 (EXIT)]
626 // CHECK-NEXT: Preds (1): B1
627 void test_for_implicit_scope() {
628 for (A a
; A b
= a
; b
.p
)
632 // CHECK: [B12 (ENTRY)]
633 // CHECK-NEXT: Succs (1): B11
635 // CHECK-NEXT: 1: [B10.4].~A() (Implicit destructor)
636 // CHECK-NEXT: 2: [B10.4] (Lifetime ends)
637 // CHECK-NEXT: 3: [B11.4].~A() (Implicit destructor)
638 // CHECK-NEXT: 4: [B11.4] (Lifetime ends)
639 // CHECK-NEXT: 5: (CXXConstructExpr, [B1.6], A)
640 // CHECK-NEXT: 6: A f;
641 // CHECK-NEXT: 7: [B1.6].~A() (Implicit destructor)
642 // CHECK-NEXT: 8: [B1.6] (Lifetime ends)
643 // CHECK-NEXT: 9: [B11.2].~A() (Implicit destructor)
644 // CHECK-NEXT: 10: [B11.2] (Lifetime ends)
645 // CHECK-NEXT: Preds (2): B8 B10
646 // CHECK-NEXT: Succs (1): B0
648 // CHECK-NEXT: 1: [B10.4].~A() (Implicit destructor)
649 // CHECK-NEXT: 2: [B10.4] (Lifetime ends)
650 // CHECK-NEXT: Preds (2): B3 B6
651 // CHECK-NEXT: Succs (1): B10
653 // CHECK-NEXT: 1: (CXXConstructExpr, [B3.2], A)
654 // CHECK-NEXT: 2: A e;
655 // CHECK-NEXT: 3: [B3.2].~A() (Implicit destructor)
656 // CHECK-NEXT: 4: [B3.2] (Lifetime ends)
657 // CHECK-NEXT: 5: [B9.2].~A() (Implicit destructor)
658 // CHECK-NEXT: 6: [B9.2] (Lifetime ends)
659 // CHECK-NEXT: Preds (1): B5
660 // CHECK-NEXT: Succs (1): B2
662 // CHECK-NEXT: 1: return;
663 // CHECK-NEXT: 2: [B9.2].~A() (Implicit destructor)
664 // CHECK-NEXT: 3: [B9.2] (Lifetime ends)
665 // CHECK-NEXT: 4: [B10.4].~A() (Implicit destructor)
666 // CHECK-NEXT: 5: [B10.4] (Lifetime ends)
667 // CHECK-NEXT: 6: [B11.4].~A() (Implicit destructor)
668 // CHECK-NEXT: 7: [B11.4] (Lifetime ends)
669 // CHECK-NEXT: 8: [B11.2].~A() (Implicit destructor)
670 // CHECK-NEXT: 9: [B11.2] (Lifetime ends)
671 // CHECK-NEXT: Preds (1): B5
672 // CHECK-NEXT: Succs (1): B0
675 // CHECK-NEXT: 2: [B5.1] (ImplicitCastExpr, LValueToRValue, _Bool)
676 // CHECK-NEXT: T: if [B5.2]
677 // CHECK-NEXT: Preds (1): B7
678 // CHECK-NEXT: Succs (2): B4 B3
680 // CHECK-NEXT: 1: [B9.2].~A() (Implicit destructor)
681 // CHECK-NEXT: 2: [B9.2] (Lifetime ends)
682 // CHECK-NEXT: T: continue;
683 // CHECK-NEXT: Preds (1): B7
684 // CHECK-NEXT: Succs (1): B2
687 // CHECK-NEXT: 2: [B7.1] (ImplicitCastExpr, LValueToRValue, _Bool)
688 // CHECK-NEXT: T: if [B7.2]
689 // CHECK-NEXT: Preds (1): B9
690 // CHECK-NEXT: Succs (2): B6 B5
692 // CHECK-NEXT: 1: [B9.2].~A() (Implicit destructor)
693 // CHECK-NEXT: 2: [B9.2] (Lifetime ends)
694 // CHECK-NEXT: T: break;
695 // CHECK-NEXT: Preds (1): B9
696 // CHECK-NEXT: Succs (1): B1
698 // CHECK-NEXT: 1: (CXXConstructExpr, [B9.2], A)
699 // CHECK-NEXT: 2: A d;
701 // CHECK-NEXT: 4: [B9.3] (ImplicitCastExpr, LValueToRValue, _Bool)
702 // CHECK-NEXT: T: if [B9.4]
703 // CHECK-NEXT: Preds (1): B10
704 // CHECK-NEXT: Succs (2): B8 B7
707 // CHECK-NEXT: 2: [B10.1] (ImplicitCastExpr, NoOp, const A)
708 // CHECK-NEXT: 3: [B10.2] (CXXConstructExpr, [B10.4], A)
709 // CHECK-NEXT: 4: A c = b;
711 // CHECK-NEXT: 6: [B10.5] (ImplicitCastExpr, NoOp, const class A)
712 // CHECK-NEXT: 7: [B10.6].operator int
713 // CHECK-NEXT: 8: [B10.6]
714 // CHECK-NEXT: 9: [B10.8] (ImplicitCastExpr, UserDefinedConversion, int)
715 // CHECK-NEXT: 10: [B10.9] (ImplicitCastExpr, IntegralToBoolean, _Bool)
716 // CHECK-NEXT: T: for (...; [B10.10]; )
717 // CHECK-NEXT: Preds (2): B2 B11
718 // CHECK-NEXT: Succs (2): B9 B1
720 // CHECK-NEXT: 1: (CXXConstructExpr, [B11.2], A)
721 // CHECK-NEXT: 2: A a;
722 // CHECK-NEXT: 3: (CXXConstructExpr, [B11.4], A)
723 // CHECK-NEXT: 4: A b;
724 // CHECK-NEXT: Preds (1): B12
725 // CHECK-NEXT: Succs (1): B10
726 // CHECK: [B0 (EXIT)]
727 // CHECK-NEXT: Preds (2): B1 B4
728 void test_for_jumps() {
730 for (A b
; A c
= b
; ) {
743 // CHECK: [B9 (ENTRY)]
744 // CHECK-NEXT: Succs (1): B8
746 // CHECK-NEXT: 1: [B7.4].~A() (Implicit destructor)
747 // CHECK-NEXT: 2: [B7.4] (Lifetime ends)
748 // CHECK-NEXT: 3: [B8.2].~A() (Implicit destructor)
749 // CHECK-NEXT: 4: [B8.2] (Lifetime ends)
750 // CHECK-NEXT: Preds (1): B7
751 // CHECK-NEXT: Succs (1): B0
753 // CHECK-NEXT: 1: [B5.4] ? [B3.3] : [B4.2]
754 // CHECK-NEXT: 2: [B7.4].~A() (Implicit destructor)
755 // CHECK-NEXT: 3: [B7.4] (Lifetime ends)
756 // CHECK-NEXT: Preds (2): B3 B4
757 // CHECK-NEXT: Succs (1): B7
760 // CHECK-NEXT: 2: [B3.1].p
761 // CHECK-NEXT: 3: [B3.2]++
762 // CHECK-NEXT: Preds (1): B5
763 // CHECK-NEXT: Succs (1): B2
766 // CHECK-NEXT: 2: [B4.1] (ImplicitCastExpr, NullToPointer, int *)
767 // CHECK-NEXT: Preds (1): B5
768 // CHECK-NEXT: Succs (1): B2
771 // CHECK-NEXT: 2: [B5.1].p
772 // CHECK-NEXT: 3: [B5.2] (ImplicitCastExpr, LValueToRValue, int *)
773 // CHECK-NEXT: 4: [B5.3] (ImplicitCastExpr, PointerToBoolean, _Bool)
774 // CHECK-NEXT: T: [B5.4] ? ... : ...
775 // CHECK-NEXT: Preds (1): B6
776 // CHECK-NEXT: Succs (2): B3 B4
779 // CHECK-NEXT: 2: (void)[B6.1] (CStyleCastExpr, ToVoid, void)
780 // CHECK-NEXT: Preds (1): B7
781 // CHECK-NEXT: Succs (1): B5
784 // CHECK-NEXT: 2: [B7.1] (ImplicitCastExpr, NoOp, const A)
785 // CHECK-NEXT: 3: [B7.2] (CXXConstructExpr, [B7.4], A)
786 // CHECK-NEXT: 4: A b = a;
788 // CHECK-NEXT: 6: [B7.5] (ImplicitCastExpr, NoOp, const class A)
789 // CHECK-NEXT: 7: [B7.6].operator int
790 // CHECK-NEXT: 8: [B7.6]
791 // CHECK-NEXT: 9: [B7.8] (ImplicitCastExpr, UserDefinedConversion, int)
792 // CHECK-NEXT: 10: [B7.9] (ImplicitCastExpr, IntegralToBoolean, _Bool)
793 // CHECK-NEXT: T: for (...; [B7.10]; ...)
794 // CHECK-NEXT: Preds (2): B2 B8
795 // CHECK-NEXT: Succs (2): B6 B1
797 // CHECK-NEXT: 1: (CXXConstructExpr, [B8.2], A)
798 // CHECK-NEXT: 2: A a;
799 // CHECK-NEXT: Preds (1): B9
800 // CHECK-NEXT: Succs (1): B7
801 void test_for_inc_conditional() {
802 for (A a
; A b
= a
; b
.p
? b
.p
++ : 0)
806 // CHECK: [B2 (ENTRY)]
807 // CHECK-NEXT: Succs (1): B1
809 // CHECK-NEXT: 1: (CXXConstructExpr, [B1.2], A)
810 // CHECK-NEXT: 2: A a;
811 // CHECK-NEXT: 3: int n;
813 // CHECK-NEXT: 5: &[B1.4]
815 // CHECK-NEXT: 7: [B1.6].p
816 // CHECK-NEXT: 8: [B1.7] = [B1.5]
817 // CHECK-NEXT: 9: [B1.2].~A() (Implicit destructor)
818 // CHECK-NEXT: 10: [B1.2] (Lifetime ends)
819 // CHECK-NEXT: 11: [B1.3] (Lifetime ends)
820 // CHECK-NEXT: Preds (1): B2
821 // CHECK-NEXT: Succs (1): B0
822 // CHECK: [B0 (EXIT)]
823 // CHECK-NEXT: Preds (1): B1
824 void test_trivial_vs_non_trivial_order() {
830 // CHECK: [B4 (ENTRY)]
831 // CHECK-NEXT: Succs (1): B3
836 // CHECK-NEXT: 3: [B1.2] = [B1.1]
837 // CHECK-NEXT: 4: [B2.1] (Lifetime ends)
838 // CHECK-NEXT: Preds (2): B2 B3
839 // CHECK-NEXT: Succs (1): B0
841 // CHECK-NEXT: 1: int i;
842 // CHECK-NEXT: Succs (1): B1
844 // CHECK-NEXT: T: goto a;
845 // CHECK-NEXT: Preds (1): B4
846 // CHECK-NEXT: Succs (1): B1
847 // CHECK: [B0 (EXIT)]
848 // CHECK-NEXT: Preds (1): B1
849 void goto_past_declaration() {
856 // CHECK: [B4 (ENTRY)]
857 // CHECK-NEXT: Succs (1): B3
862 // CHECK-NEXT: 3: [B1.2] = [B1.1]
863 // CHECK-NEXT: 4: [B2.4] (Lifetime ends)
864 // CHECK-NEXT: Preds (2): B2 B3
865 // CHECK-NEXT: Succs (1): B0
867 // CHECK-NEXT: 1: int j;
868 // CHECK-NEXT: 2: [B2.1] (Lifetime ends)
869 // CHECK-NEXT: 3: [B3.1] (Lifetime ends)
870 // CHECK-NEXT: 4: int k;
871 // CHECK-NEXT: Succs (1): B1
873 // CHECK-NEXT: 1: int i;
874 // CHECK-NEXT: 2: [B3.1] (Lifetime ends)
875 // CHECK-NEXT: T: goto a;
876 // CHECK-NEXT: Preds (1): B4
877 // CHECK-NEXT: Succs (1): B1
878 // CHECK: [B0 (EXIT)]
879 // CHECK-NEXT: Preds (1): B1
880 void goto_past_declaration2() {
897 // CHECK: [B5 (ENTRY)]
898 // CHECK-NEXT: Succs (1): B3
901 // CHECK-NEXT: 2: [B1.1]++
902 // CHECK-NEXT: 3: [B2.4].~B() (Implicit destructor)
903 // CHECK-NEXT: 4: [B2.4] (Lifetime ends)
904 // CHECK-NEXT: 5: [B2.2].~B() (Implicit destructor)
905 // CHECK-NEXT: 6: [B2.2] (Lifetime ends)
906 // CHECK-NEXT: 7: [B3.1] (Lifetime ends)
907 // CHECK-NEXT: Succs (1): B0
909 // CHECK-NEXT: label:
910 // CHECK-NEXT: 1: (CXXConstructExpr, [B2.2], B)
911 // CHECK-NEXT: 2: B b1;
912 // CHECK-NEXT: 3: (CXXConstructExpr, [B2.4], B)
913 // CHECK-NEXT: 4: B b2;
914 // CHECK-NEXT: Preds (2): B3 B4
915 // CHECK-NEXT: Succs (1): B4
917 // CHECK-NEXT: 1: int i;
918 // CHECK-NEXT: Preds (1): B5
919 // CHECK-NEXT: Succs (1): B2
921 // CHECK-NEXT: 1: [B2.4].~B() (Implicit destructor)
922 // CHECK-NEXT: 2: [B2.4] (Lifetime ends)
923 // CHECK-NEXT: 3: [B2.2].~B() (Implicit destructor)
924 // CHECK-NEXT: 4: [B2.2] (Lifetime ends)
925 // CHECK-NEXT: T: goto label;
926 // CHECK-NEXT: Preds (1): B2
927 // CHECK-NEXT: Succs (1): B2
928 // CHECK: [B0 (EXIT)]
929 // CHECK-NEXT: Preds (1): B1
930 int backpatched_goto() {