File: expr-inspection.c

package info (click to toggle)
llvm-toolchain-13 1%3A13.0.1-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,418,840 kB
  • sloc: cpp: 5,290,826; ansic: 996,570; asm: 544,593; python: 188,212; objc: 72,027; lisp: 30,291; f90: 25,395; sh: 24,898; javascript: 9,780; pascal: 9,398; perl: 7,484; ml: 5,432; awk: 3,523; makefile: 2,913; xml: 953; cs: 573; fortran: 539
file content (56 lines) | stat: -rw-r--r-- 2,005 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// RUN: %clang_analyze_cc1 \
// RUN:  -analyzer-checker=debug.ExprInspection \
// RUN:  -verify %s 2>&1 | FileCheck %s

// Self-tests for the debug.ExprInspection checker.

void clang_analyzer_dump(int x);
void clang_analyzer_dump_pointer(int *p);
void clang_analyzer_printState();
void clang_analyzer_numTimesReached();

void foo(int x) {
  clang_analyzer_dump(x); // expected-warning{{reg_$0<int x>}}
  clang_analyzer_dump(x + (-1)); // expected-warning{{(reg_$0<int x>) + -1}}
  int y = 1;
  for (; y < 3; ++y) {
    clang_analyzer_numTimesReached(); // expected-warning{{2}}

    if (y == 2) {
      int z = x > 13;
      if (!z)
        clang_analyzer_printState();
    }
  }
}

// CHECK:      "program_state": {
// CHECK-NEXT:   "store": { "pointer": "{{0x[0-9a-f]+}}", "items": [
// CHECK-NEXT:     { "cluster": "y", "pointer": "{{0x[0-9a-f]+}}", "items": [
// CHECK-NEXT:       { "kind": "Direct", "offset": 0, "value": "2 S32b" }
// CHECK-NEXT:     ]}
// CHECK-NEXT:   ]},
// CHECK-NEXT:   "environment": { "pointer": "{{0x[0-9a-f]+}}", "items": [
// CHECK-NEXT:     { "lctx_id": {{[0-9]+}}, "location_context": "#0 Call", "calling": "foo", "location": null, "items": [
// CHECK-NEXT:       { "stmt_id": {{[0-9]+}}, "pretty": "clang_analyzer_printState", "value": "&code{clang_analyzer_printState}" }
// CHECK-NEXT:     ]}
// CHECK-NEXT:   ]},
// CHECK-NEXT:   "constraints": [
// CHECK-NEXT:     { "symbol": "reg_$0<int x>", "range": "{ [-2147483648, 13] }" }
// CHECK-NEXT:   ],
// CHECK-NEXT:   "equivalence_classes": null,
// CHECK-NEXT:   "disequality_info": null,
// CHECK-NEXT:   "dynamic_types": null,
// CHECK-NEXT:   "dynamic_casts": null,
// CHECK-NEXT:   "constructing_objects": null,
// CHECK-NEXT:   "checker_messages": null
// CHECK-NEXT: }

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}}
  clang_analyzer_dump_pointer(&p->x); // expected-warning{{&SymRegion{reg_$1<struct S * p>}.x}}
}