1 // RUN: %clang_analyze_cc1 \
2 // RUN: -analyzer-checker=debug.ExprInspection \
3 // RUN: -verify %s 2>&1 | FileCheck %s
4
5 // Self-tests for the debug.ExprInspection checker.
6
7 void clang_analyzer_dump(int x);
8 void clang_analyzer_dump_pointer(int *p);
9 void clang_analyzer_printState();
10 void clang_analyzer_numTimesReached();
11
foo(int x)12 void foo(int x) {
13 clang_analyzer_dump(x); // expected-warning{{reg_$0<int x>}}
14 clang_analyzer_dump(x + (-1)); // expected-warning{{(reg_$0<int x>) + -1}}
15 int y = 1;
16 for (; y < 3; ++y) {
17 clang_analyzer_numTimesReached(); // expected-warning{{2}}
18
19 if (y == 2) {
20 int z = x > 13;
21 if (!z)
22 clang_analyzer_printState();
23 }
24 }
25 }
26
27 // CHECK: "program_state": {
28 // CHECK-NEXT: "store": { "pointer": "{{0x[0-9a-f]+}}", "items": [
29 // CHECK-NEXT: { "cluster": "y", "pointer": "{{0x[0-9a-f]+}}", "items": [
30 // CHECK-NEXT: { "kind": "Direct", "offset": 0, "value": "2 S32b" }
31 // CHECK-NEXT: ]}
32 // CHECK-NEXT: ]},
33 // CHECK-NEXT: "environment": { "pointer": "{{0x[0-9a-f]+}}", "items": [
34 // CHECK-NEXT: { "lctx_id": {{[0-9]+}}, "location_context": "#0 Call", "calling": "foo", "location": null, "items": [
35 // CHECK-NEXT: { "stmt_id": {{[0-9]+}}, "pretty": "clang_analyzer_printState", "value": "&code{clang_analyzer_printState}" }
36 // CHECK-NEXT: ]}
37 // CHECK-NEXT: ]},
38 // CHECK-NEXT: "constraints": [
39 // CHECK-NEXT: { "symbol": "reg_$0<int x>", "range": "{ [-2147483648, 13] }" }
40 // CHECK-NEXT: ],
41 // CHECK-NEXT: "dynamic_types": null,
42 // CHECK-NEXT: "dynamic_casts": null,
43 // CHECK-NEXT: "constructing_objects": null,
44 // CHECK-NEXT: "checker_messages": null
45 // CHECK-NEXT: }
46
47 struct S {
48 int x, y;
49 };
50
test_field_dumps(struct S s,struct S * p)51 void test_field_dumps(struct S s, struct S *p) {
52 clang_analyzer_dump_pointer(&s.x); // expected-warning{{&s.x}}
53 clang_analyzer_dump_pointer(&p->x); // expected-warning{{&SymRegion{reg_$1<struct S * p>}.x}}
54 }
55