2019-05-29 23:25:19 +08:00
|
|
|
// RUN: %clang_analyze_cc1 \
|
|
|
|
// RUN: -analyzer-checker=debug.ExprInspection \
|
|
|
|
// RUN: -verify %s 2>&1 | FileCheck %s
|
2016-12-01 01:57:18 +08:00
|
|
|
|
|
|
|
// Self-tests for the debug.ExprInspection checker.
|
|
|
|
|
|
|
|
void clang_analyzer_dump(int x);
|
2019-10-19 04:15:39 +08:00
|
|
|
void clang_analyzer_dump_pointer(int *p);
|
2016-12-01 01:57:18 +08:00
|
|
|
void clang_analyzer_printState();
|
|
|
|
void clang_analyzer_numTimesReached();
|
|
|
|
|
|
|
|
void foo(int x) {
|
2016-12-06 04:30:11 +08:00
|
|
|
clang_analyzer_dump(x); // expected-warning{{reg_$0<int x>}}
|
2017-10-19 19:58:21 +08:00
|
|
|
clang_analyzer_dump(x + (-1)); // expected-warning{{(reg_$0<int x>) + -1}}
|
2016-12-01 01:57:18 +08:00
|
|
|
int y = 1;
|
2019-05-29 23:25:19 +08:00
|
|
|
for (; y < 3; ++y) {
|
2016-12-01 01:57:18 +08:00
|
|
|
clang_analyzer_numTimesReached(); // expected-warning{{2}}
|
2019-05-29 23:25:19 +08:00
|
|
|
|
|
|
|
if (y == 2) {
|
|
|
|
int z = x > 13;
|
|
|
|
if (!z)
|
|
|
|
clang_analyzer_printState();
|
|
|
|
}
|
|
|
|
}
|
2016-12-01 01:57:18 +08:00
|
|
|
}
|
|
|
|
|
2019-05-30 00:22:21 +08:00
|
|
|
// CHECK: "program_state": {
|
2019-06-25 11:17:55 +08:00
|
|
|
// CHECK-NEXT: "store": { "pointer": "{{0x[0-9a-f]+}}", "items": [
|
2019-06-20 07:33:51 +08:00
|
|
|
// CHECK-NEXT: { "cluster": "y", "pointer": "{{0x[0-9a-f]+}}", "items": [
|
2019-05-30 00:22:21 +08:00
|
|
|
// CHECK-NEXT: { "kind": "Direct", "offset": 0, "value": "2 S32b" }
|
|
|
|
// CHECK-NEXT: ]}
|
2019-06-25 11:17:55 +08:00
|
|
|
// CHECK-NEXT: ]},
|
|
|
|
// CHECK-NEXT: "environment": { "pointer": "{{0x[0-9a-f]+}}", "items": [
|
2019-10-19 04:15:39 +08:00
|
|
|
// CHECK-NEXT: { "lctx_id": {{[0-9]+}}, "location_context": "#0 Call", "calling": "foo", "location": null, "items": [
|
2019-06-20 07:33:48 +08:00
|
|
|
// CHECK-NEXT: { "stmt_id": {{[0-9]+}}, "pretty": "clang_analyzer_printState", "value": "&code{clang_analyzer_printState}" }
|
2019-05-30 00:22:21 +08:00
|
|
|
// CHECK-NEXT: ]}
|
2019-06-25 11:17:55 +08:00
|
|
|
// CHECK-NEXT: ]},
|
2019-05-30 00:22:21 +08:00
|
|
|
// CHECK-NEXT: "constraints": [
|
|
|
|
// CHECK-NEXT: { "symbol": "reg_$0<int x>", "range": "{ [-2147483648, 13] }" }
|
|
|
|
// CHECK-NEXT: ],
|
|
|
|
// CHECK-NEXT: "dynamic_types": null,
|
2019-08-22 08:20:36 +08:00
|
|
|
// CHECK-NEXT: "dynamic_casts": null,
|
2019-05-30 00:22:21 +08:00
|
|
|
// CHECK-NEXT: "constructing_objects": null,
|
|
|
|
// CHECK-NEXT: "checker_messages": null
|
|
|
|
// CHECK-NEXT: }
|
2019-05-30 00:02:33 +08:00
|
|
|
|
2019-10-19 04:15:39 +08:00
|
|
|
struct S {
|
|
|
|
int x, y;
|
|
|
|
};
|
|
|
|
|
|
|
|
void test_field_dumps(struct S s, struct S *p) {
|
|
|
|
clang_analyzer_dump_pointer(&s.x); // expected-warning{{&s.x}}
|
2019-12-10 08:26:38 +08:00
|
|
|
clang_analyzer_dump_pointer(&p->x); // expected-warning{{&SymRegion{reg_$1<struct S * p>}.x}}
|
2019-10-19 04:15:39 +08:00
|
|
|
}
|