1 // RUN: %clang_analyze_cc1 -w -analyzer-checker=debug.DumpLiveExprs %s 2>&1\
7 int testThatDumperWorks(int x
, int y
, int z
) {
14 // [B4 (x)] ? [B2 (y)] : [B3 (z)]
18 // [B1] --> [B0 (EXIT)]
21 // CHECK: [ B0 (live expressions at block exit) ]
24 // CHECK: [ B1 (live expressions at block exit) ]
27 // CHECK: [ B2 (live expressions at block exit) ]
29 // CHECK-NEXT: DeclRefExpr {{.*}} 'y' 'int'
31 // CHECK-NEXT: DeclRefExpr {{.*}} 'z' 'int'
33 // CHECK-NEXT: ImplicitCastExpr {{.*}} <IntegralToBoolean>
34 // CHECK-NEXT: `-ImplicitCastExpr {{.*}} <LValueToRValue>
35 // CHECK-NEXT: `-DeclRefExpr {{.*}} 'x' 'int'
38 // CHECK: [ B3 (live expressions at block exit) ]
40 // CHECK-NEXT: DeclRefExpr {{.*}} 'y' 'int'
42 // CHECK-NEXT: DeclRefExpr {{.*}} 'z' 'int'
44 // CHECK-NEXT: ImplicitCastExpr {{.*}} <IntegralToBoolean>
45 // CHECK-NEXT: `-ImplicitCastExpr {{.*}} <LValueToRValue>
46 // CHECK-NEXT: `-DeclRefExpr {{.*}} 'x' 'int'
47 // CHECK: [ B4 (live expressions at block exit) ]
49 // CHECK-NEXT: DeclRefExpr {{.*}} 'y' 'int'
51 // CHECK-NEXT: DeclRefExpr {{.*}} 'z' 'int'
53 // CHECK-NEXT: ImplicitCastExpr {{.*}} <IntegralToBoolean>
54 // CHECK-NEXT: `-ImplicitCastExpr {{.*}} <LValueToRValue>
55 // CHECK-NEXT: `-DeclRefExpr {{.*}} 'x' 'int'
58 // CHECK: [ B5 (live expressions at block exit) ]
60 // CHECK-NEXT: DeclRefExpr {{.*}} 'y' 'int'
62 // CHECK-NEXT: DeclRefExpr {{.*}} 'z' 'int'
67 void testIfBranchExpression(bool flag
) {
68 // No expressions should be carried over from one block to another here.
75 // CHECK: [ B0 (live expressions at block exit) ]
78 // CHECK: [ B1 (live expressions at block exit) ]
81 // CHECK: [ B2 (live expressions at block exit) ]
84 // CHECK: [ B3 (live expressions at block exit) ]
87 // CHECK: [ B4 (live expressions at block exit) ]
90 // CHECK: [ B5 (live expressions at block exit) ]
95 void testWhileBodyExpression(bool flag
) {
96 // No expressions should be carried over from one block to another here.
103 // CHECK: [ B0 (live expressions at block exit) ]
106 // CHECK: [ B1 (live expressions at block exit) ]
109 // CHECK: [ B2 (live expressions at block exit) ]
112 // CHECK: [ B3 (live expressions at block exit) ]
115 // CHECK: [ B4 (live expressions at block exit) ]
118 // CHECK: [ B5 (live expressions at block exit) ]
123 void testDoWhileBodyExpression(bool flag
) {
124 // No expressions should be carried over from one block to another here.
132 // CHECK: [ B0 (live expressions at block exit) ]
135 // CHECK: [ B1 (live expressions at block exit) ]
138 // CHECK: [ B2 (live expressions at block exit) ]
141 // CHECK: [ B3 (live expressions at block exit) ]
144 // CHECK: [ B4 (live expressions at block exit) ]
147 // CHECK: [ B5 (live expressions at block exit) ]
152 void testForBodyExpression(bool flag
) {
153 // No expressions should be carried over from one block to another here.
160 // CHECK: [ B0 (live expressions at block exit) ]
163 // CHECK: [ B1 (live expressions at block exit) ]
166 // CHECK: [ B2 (live expressions at block exit) ]
169 // CHECK: [ B3 (live expressions at block exit) ]
172 // CHECK: [ B4 (live expressions at block exit) ]
175 // CHECK: [ B5 (live expressions at block exit) ]
179 void clang_analyzer_eval(bool);
181 void test_lambda_refcapture() {
183 [&](int &a
) { a
= 42; }(a
);
184 clang_analyzer_eval(a
== 42); // expected-warning{{TRUE}}
187 // CHECK: [ B0 (live expressions at block exit) ]
190 // CHECK-NEXT: [ B1 (live expressions at block exit) ]
193 // CHECK-NEXT: [ B2 (live expressions at block exit) ]
197 int logicalOpInTernary(bool b
) {
198 return (b
|| b
) ? 0 : 1;
208 // [B4 (b||b)] ? [B2 (0)] : [B3 (1)]
212 // [B1] --> [B0 (EXIT)]
215 // CHECK: [ B0 (live expressions at block exit) ]
218 // CHECK: [ B1 (live expressions at block exit) ]
221 // CHECK: [ B2 (live expressions at block exit) ]
223 // CHECK: ImplicitCastExpr {{.*}} '_Bool' <LValueToRValue>
224 // CHECK: `-DeclRefExpr {{.*}} '_Bool' lvalue ParmVar {{.*}} 'b' '_Bool'
226 // CHECK: ImplicitCastExpr {{.*}} '_Bool' <LValueToRValue>
227 // CHECK: `-DeclRefExpr {{.*}} '_Bool' lvalue ParmVar {{.*}} 'b' '_Bool'
229 // CHECK: BinaryOperator {{.*}} '_Bool' '||'
230 // CHECK: |-ImplicitCastExpr {{.*}} '_Bool' <LValueToRValue>
231 // CHECK: | `-DeclRefExpr {{.*}} '_Bool' lvalue ParmVar {{.*}} 'b' '_Bool'
232 // CHECK: `-ImplicitCastExpr {{.*}} '_Bool' <LValueToRValue>
233 // CHECK: `-DeclRefExpr {{.*}} '_Bool' lvalue ParmVar {{.*}} 'b' '_Bool'
235 // CHECK: IntegerLiteral {{.*}} 'int' 0
237 // CHECK: IntegerLiteral {{.*}} 'int' 1
240 // CHECK: [ B3 (live expressions at block exit) ]
242 // CHECK: ImplicitCastExpr {{.*}} '_Bool' <LValueToRValue>
243 // CHECK: `-DeclRefExpr {{.*}} '_Bool' lvalue ParmVar {{.*}} 'b' '_Bool'
245 // CHECK: ImplicitCastExpr {{.*}} '_Bool' <LValueToRValue>
246 // CHECK: `-DeclRefExpr {{.*}} '_Bool' lvalue ParmVar {{.*}} 'b' '_Bool'
248 // CHECK: BinaryOperator {{.*}} '_Bool' '||'
249 // CHECK: |-ImplicitCastExpr {{.*}} '_Bool' <LValueToRValue>
250 // CHECK: | `-DeclRefExpr {{.*}} '_Bool' lvalue ParmVar {{.*}} 'b' '_Bool'
251 // CHECK: `-ImplicitCastExpr {{.*}} '_Bool' <LValueToRValue>
252 // CHECK: `-DeclRefExpr {{.*}} '_Bool' lvalue ParmVar {{.*}} 'b' '_Bool'
254 // CHECK: IntegerLiteral {{.*}} 'int' 0
256 // CHECK: IntegerLiteral {{.*}} 'int' 1
259 // CHECK: [ B4 (live expressions at block exit) ]
261 // CHECK: ImplicitCastExpr {{.*}} '_Bool' <LValueToRValue>
262 // CHECK: `-DeclRefExpr {{.*}} '_Bool' lvalue ParmVar {{.*}} 'b' '_Bool'
264 // CHECK: ImplicitCastExpr {{.*}} '_Bool' <LValueToRValue>
265 // CHECK: `-DeclRefExpr {{.*}} '_Bool' lvalue ParmVar {{.*}} 'b' '_Bool'
267 // CHECK: BinaryOperator {{.*}} '_Bool' '||'
268 // CHECK: |-ImplicitCastExpr {{.*}} '_Bool' <LValueToRValue>
269 // CHECK: | `-DeclRefExpr {{.*}} '_Bool' lvalue ParmVar {{.*}} 'b' '_Bool'
270 // CHECK: `-ImplicitCastExpr {{.*}} '_Bool' <LValueToRValue>
271 // CHECK: `-DeclRefExpr {{.*}} '_Bool' lvalue ParmVar {{.*}} 'b' '_Bool'
273 // CHECK: IntegerLiteral {{.*}} 'int' 0
275 // CHECK: IntegerLiteral {{.*}} 'int' 1
278 // CHECK: [ B5 (live expressions at block exit) ]
280 // CHECK: ImplicitCastExpr {{.*}} '_Bool' <LValueToRValue>
281 // CHECK: `-DeclRefExpr {{.*}} '_Bool' lvalue ParmVar {{.*}} 'b' '_Bool'
283 // CHECK: ImplicitCastExpr {{.*}} '_Bool' <LValueToRValue>
284 // CHECK: `-DeclRefExpr {{.*}} '_Bool' lvalue ParmVar {{.*}} 'b' '_Bool'
286 // CHECK: BinaryOperator {{.*}} '_Bool' '||'
287 // CHECK: |-ImplicitCastExpr {{.*}} '_Bool' <LValueToRValue>
288 // CHECK: | `-DeclRefExpr {{.*}} '_Bool' lvalue ParmVar {{.*}} 'b' '_Bool'
289 // CHECK: `-ImplicitCastExpr {{.*}} '_Bool' <LValueToRValue>
290 // CHECK: `-DeclRefExpr {{.*}} '_Bool' lvalue ParmVar {{.*}} 'b' '_Bool'
292 // CHECK: IntegerLiteral {{.*}} 'int' 0
294 // CHECK: IntegerLiteral {{.*}} 'int' 1
297 // CHECK: [ B6 (live expressions at block exit) ]
299 // CHECK: ImplicitCastExpr {{.*}} '_Bool' <LValueToRValue>
300 // CHECK: `-DeclRefExpr {{.*}} '_Bool' lvalue ParmVar {{.*}} 'b' '_Bool'
302 // CHECK: IntegerLiteral {{.*}} 'int' 0
304 // CHECK: IntegerLiteral {{.*}} 'int' 1