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