1 // RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpCFG -analyzer-config cfg-loopexit=true %s > %t 2>&1
2 // RUN: FileCheck --input-file=%t %s
5 // CHECK-NEXT: Succs (1): B5
8 // CHECK-NEXT: 1: ForStmt (LoopExit)
9 // CHECK-NEXT: 2: return;
10 // CHECK-NEXT: Preds (1): B4
11 // CHECK-NEXT: Succs (1): B0
15 // CHECK-NEXT: 2: [B2.1]++
16 // CHECK-NEXT: Preds (1): B3
17 // CHECK-NEXT: Succs (1): B4
21 // CHECK-NEXT: 2: [B3.1]++
22 // CHECK-NEXT: Preds (1): B4
23 // CHECK-NEXT: Succs (1): B2
27 // CHECK-NEXT: 2: [B4.1] (ImplicitCastExpr, LValueToRValue, int)
29 // CHECK-NEXT: 4: [B4.2] < [B4.3]
30 // CHECK-NEXT: T: for (...; [B4.4]; ...)
31 // CHECK-NEXT: Preds (2): B2 B5
32 // CHECK-NEXT: Succs (2): B3 B1
36 // CHECK-NEXT: 2: int i = 0;
37 // CHECK-NEXT: Preds (1): B6
38 // CHECK-NEXT: Succs (1): B4
41 // CHECK-NEXT: Preds (1): B1
42 void check_forloop1() {
43 for (int i
= 0; i
< 12; i
++) {
49 // CHECK: [B4 (ENTRY)]
50 // CHECK-NEXT: Succs (1): B3
53 // CHECK-NEXT: 1: ForStmt (LoopExit)
54 // CHECK-NEXT: Succs (1): B0
57 // CHECK-NEXT: Preds (1): B3
58 // CHECK-NEXT: Succs (1): B3
61 // CHECK-NEXT: T: for (; ; )
62 // CHECK-NEXT: Preds (2): B2 B4
63 // CHECK-NEXT: Succs (2): B2 NULL
66 // CHECK-NEXT: Preds (1): B1
67 void check_forloop2() {
72 // CHECK: [B5 (ENTRY)]
73 // CHECK-NEXT: Succs (1): B4
76 // CHECK-NEXT: 1: WhileStmt (LoopExit)
77 // CHECK-NEXT: Succs (1): B0
80 // CHECK-NEXT: Preds (1): B3
81 // CHECK-NEXT: Succs (1): B4
84 // CHECK-NEXT: 1: int i;
85 // CHECK-NEXT: Preds (1): B4
86 // CHECK-NEXT: Succs (1): B2
89 // CHECK-NEXT: 1: true
90 // CHECK-NEXT: T: while [B4.1]
91 // CHECK-NEXT: Preds (2): B2 B5
92 // CHECK-NEXT: Succs (2): B3 NULL
95 // CHECK-NEXT: Preds (1): B1
102 // CHECK: [B5 (ENTRY)]
103 // CHECK-NEXT: Succs (1): B4
106 // CHECK-NEXT: 1: WhileStmt (LoopExit)
108 // CHECK-NEXT: 3: int k = 2;
109 // CHECK-NEXT: 4: return;
110 // CHECK-NEXT: Preds (1): B3
111 // CHECK-NEXT: Succs (1): B0
114 // CHECK-NEXT: Preds (1): B3
115 // CHECK-NEXT: Succs (1): B3
119 // CHECK-NEXT: 2: [B3.1] (ImplicitCastExpr, LValueToRValue, int)
121 // CHECK-NEXT: 4: [B3.2] < [B3.3]
122 // CHECK-NEXT: T: while [B3.4]
123 // CHECK-NEXT: Preds (2): B2 B4
124 // CHECK-NEXT: Succs (2): B2 B1
127 // CHECK-NEXT: 1: int l;
128 // CHECK-NEXT: Preds (1): B5
129 // CHECK-NEXT: Succs (1): B3
131 // CHECK: [B0 (EXIT)]
132 // CHECK-NEXT: Preds (1): B1
133 void check_while2() {
141 // CHECK: [B4 (ENTRY)]
142 // CHECK-NEXT: Succs (1): B3
145 // CHECK-NEXT: 1: WhileStmt (LoopExit)
146 // CHECK-NEXT: Preds (1): B3
147 // CHECK-NEXT: Succs (1): B0
150 // CHECK-NEXT: Succs (1): B3
153 // CHECK-NEXT: 1: false
154 // CHECK-NEXT: T: while [B3.1]
155 // CHECK-NEXT: Preds (2): B2 B4
156 // CHECK-NEXT: Succs (2): NULL B1
158 // CHECK: [B0 (EXIT)]
159 // CHECK-NEXT: Preds (1): B1
160 void check_while3() {
166 // CHECK: [B4 (ENTRY)]
167 // CHECK-NEXT: Succs (1): B2
170 // CHECK-NEXT: 1: DoStmt (LoopExit)
171 // CHECK-NEXT: Preds (1): B2
172 // CHECK-NEXT: Succs (1): B0
175 // CHECK-NEXT: 1: false
176 // CHECK-NEXT: T: do ... while [B2.1]
177 // CHECK-NEXT: Preds (2): B3 B4
178 // CHECK-NEXT: Succs (2): NULL B1
181 // CHECK-NEXT: Succs (1): B2
183 // CHECK: [B0 (EXIT)]
184 // CHECK-NEXT: Preds (1): B1
185 void check_dowhile1() {
190 // CHECK: [B6 (ENTRY)]
191 // CHECK-NEXT: Succs (1): B5
194 // CHECK-NEXT: 1: DoStmt (LoopExit)
196 // CHECK-NEXT: 3: [B1.2]--
197 // CHECK-NEXT: 4: return;
198 // CHECK-NEXT: Preds (1): B2
199 // CHECK-NEXT: Succs (1): B0
203 // CHECK-NEXT: 2: [B2.1] (ImplicitCastExpr, LValueToRValue, int)
205 // CHECK-NEXT: 4: [B2.2] < [B2.3]
206 // CHECK-NEXT: T: do ... while [B2.4]
207 // CHECK-NEXT: Preds (1): B3
208 // CHECK-NEXT: Succs (2): B4 B1
213 // CHECK-NEXT: 3: [B3.1] += [B3.2]
214 // CHECK-NEXT: Preds (2): B4 B5
215 // CHECK-NEXT: Succs (1): B2
218 // CHECK-NEXT: Preds (1): B2
219 // CHECK-NEXT: Succs (1): B3
223 // CHECK-NEXT: 2: int j = 2;
224 // CHECK-NEXT: Preds (1): B6
225 // CHECK-NEXT: Succs (1): B3
227 // CHECK: [B0 (EXIT)]
228 // CHECK-NEXT: Preds (1): B1
229 void check_dowhile2() {
238 // CHECK: [B10 (ENTRY)]
239 // CHECK-NEXT: Succs (1): B9
242 // CHECK-NEXT: 1: WhileStmt (LoopExit)
243 // CHECK-NEXT: Preds (1): B8
244 // CHECK-NEXT: Succs (1): B0
247 // CHECK-NEXT: Preds (1): B3
248 // CHECK-NEXT: Succs (1): B8
251 // CHECK-NEXT: 1: ForStmt (LoopExit)
252 // CHECK-NEXT: Preds (1): B6
253 // CHECK-NEXT: Succs (1): B2
257 // CHECK-NEXT: 2: [B4.1]++
258 // CHECK-NEXT: Preds (1): B5
259 // CHECK-NEXT: Succs (1): B6
263 // CHECK-NEXT: 2: [B5.1]++
264 // CHECK-NEXT: Preds (1): B6
265 // CHECK-NEXT: Succs (1): B4
269 // CHECK-NEXT: 2: [B6.1] (ImplicitCastExpr, LValueToRValue, int)
271 // CHECK-NEXT: 4: [B6.2] < [B6.3]
272 // CHECK-NEXT: T: for (...; [B6.4]; ...)
273 // CHECK-NEXT: Preds (2): B4 B7
274 // CHECK-NEXT: Succs (2): B5 B3
278 // CHECK-NEXT: 2: int j = 1;
279 // CHECK-NEXT: Preds (1): B8
280 // CHECK-NEXT: Succs (1): B6
284 // CHECK-NEXT: 2: [B8.1] (ImplicitCastExpr, LValueToRValue, int)
286 // CHECK-NEXT: 4: [B8.2] < [B8.3]
287 // CHECK-NEXT: T: while [B8.4]
288 // CHECK-NEXT: Preds (2): B2 B9
289 // CHECK-NEXT: Succs (2): B7 B1
293 // CHECK-NEXT: 2: -[B9.1]
294 // CHECK-NEXT: 3: int i = -40;
295 // CHECK-NEXT: Preds (1): B10
296 // CHECK-NEXT: Succs (1): B8
298 // CHECK: [B0 (EXIT)]
299 // CHECK-NEXT: Preds (1): B1
300 void nested_loops1() {
303 for (int j
= 1; j
< 6; j
++)
308 // CHECK: [B9 (ENTRY)]
309 // CHECK-NEXT: Succs (1): B8
312 // CHECK-NEXT: 1: ForStmt (LoopExit)
313 // CHECK-NEXT: Preds (1): B7
314 // CHECK-NEXT: Succs (1): B0
318 // CHECK-NEXT: 2: [B2.1]++
319 // CHECK-NEXT: Preds (1): B3
320 // CHECK-NEXT: Succs (1): B7
323 // CHECK-NEXT: 1: DoStmt (LoopExit)
325 // CHECK-NEXT: 3: [B3.2]--
326 // CHECK-NEXT: Preds (1): B4
327 // CHECK-NEXT: Succs (1): B2
331 // CHECK-NEXT: 2: [B4.1] (ImplicitCastExpr, LValueToRValue, int)
333 // CHECK-NEXT: 4: [B4.2] < [B4.3]
334 // CHECK-NEXT: T: do ... while [B4.4]
335 // CHECK-NEXT: Preds (1): B5
336 // CHECK-NEXT: Succs (2): B6 B3
340 // CHECK-NEXT: 2: [B5.1]++
341 // CHECK-NEXT: Preds (2): B6 B7
342 // CHECK-NEXT: Succs (1): B4
345 // CHECK-NEXT: Preds (1): B4
346 // CHECK-NEXT: Succs (1): B5
350 // CHECK-NEXT: 2: [B7.1] (ImplicitCastExpr, LValueToRValue, int)
352 // CHECK-NEXT: 4: [B7.2] < [B7.3]
353 // CHECK-NEXT: T: for (...; [B7.4]; ...)
354 // CHECK-NEXT: Preds (2): B2 B8
355 // CHECK-NEXT: Succs (2): B5 B1
359 // CHECK-NEXT: 2: -[B8.1]
360 // CHECK-NEXT: 3: int i = -40;
362 // CHECK-NEXT: 5: int j = 1;
363 // CHECK-NEXT: Preds (1): B9
364 // CHECK-NEXT: Succs (1): B7
366 // CHECK: [B0 (EXIT)]
367 // CHECK-NEXT: Preds (1): B1
368 void nested_loops2() {
370 for (int j
= 1; j
< 6; j
++) {
378 // CHECK: [B12 (ENTRY)]
379 // CHECK-NEXT: Succs (1): B11
382 // CHECK-NEXT: 1: WhileStmt (LoopExit)
383 // CHECK-NEXT: 2: return;
384 // CHECK-NEXT: Preds (2): B3 B5
385 // CHECK-NEXT: Succs (1): B0
388 // CHECK-NEXT: Preds (1): B4
389 // CHECK-NEXT: Succs (1): B5
392 // CHECK-NEXT: T: break;
393 // CHECK-NEXT: Preds (1): B4
394 // CHECK-NEXT: Succs (1): B1
398 // CHECK-NEXT: 2: [B4.1]++
400 // CHECK-NEXT: 4: [B4.3] (ImplicitCastExpr, LValueToRValue, int)
402 // CHECK-NEXT: 6: [B4.4] % [B4.5]
403 // CHECK-NEXT: 7: [B4.6] (ImplicitCastExpr, IntegralToBoolean, _Bool)
404 // CHECK-NEXT: T: if [B4.7]
405 // CHECK-NEXT: Preds (1): B5
406 // CHECK-NEXT: Succs (2): B3 B2
410 // CHECK-NEXT: 2: [B5.1] (ImplicitCastExpr, LValueToRValue, int)
412 // CHECK-NEXT: 4: [B5.2] < [B5.3]
413 // CHECK-NEXT: T: while [B5.4]
414 // CHECK-NEXT: Preds (2): B2 B6
415 // CHECK-NEXT: Succs (2): B4 B1
418 // CHECK-NEXT: 1: ForStmt (LoopExit)
420 // CHECK-NEXT: 3: int i = 1;
421 // CHECK-NEXT: Preds (2): B8 B10
422 // CHECK-NEXT: Succs (1): B5
426 // CHECK-NEXT: 2: [B7.1]++
427 // CHECK-NEXT: Preds (1): B9
428 // CHECK-NEXT: Succs (1): B10
431 // CHECK-NEXT: T: break;
432 // CHECK-NEXT: Preds (1): B9
433 // CHECK-NEXT: Succs (1): B6
437 // CHECK-NEXT: 2: [B9.1] (ImplicitCastExpr, LValueToRValue, int)
439 // CHECK-NEXT: 4: [B9.2] == [B9.3]
440 // CHECK-NEXT: T: if [B9.4]
441 // CHECK-NEXT: Preds (1): B10
442 // CHECK-NEXT: Succs (2): B8 B7
446 // CHECK-NEXT: 2: [B10.1] (ImplicitCastExpr, LValueToRValue, int)
448 // CHECK-NEXT: 4: [B10.2] < [B10.3]
449 // CHECK-NEXT: T: for (...; [B10.4]; ...)
450 // CHECK-NEXT: Preds (2): B7 B11
451 // CHECK-NEXT: Succs (2): B9 B6
455 // CHECK-NEXT: 2: int i = 2;
456 // CHECK-NEXT: Preds (1): B12
457 // CHECK-NEXT: Succs (1): B10
459 // CHECK: [B0 (EXIT)]
460 // CHECK-NEXT: Preds (1): B1
463 for(int i
= 2; i
< 6; i
++) {