| 1 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core %s -ftime-trace=%t.raw.json -ftime-trace-granularity=0 -verify |
| 2 |
// RUN: %python -c 'import json, sys; print(json.dumps(json.load(sys.stdin), indent=4))' < %t.raw.json > %t.formatted.json |
| 3 |
// RUN: FileCheck --input-file=%t.formatted.json --check-prefix=CHECK %s |
| 4 |
|
| 5 |
// The trace file is rather large, but it should contain at least the duration of the analysis of 'f': |
| 6 |
// |
| 7 |
// CHECK: "name": "HandleCode f", |
| 8 |
// CHECK-NEXT: "args": { |
| 9 |
// CHECK-NEXT: "detail": "f()", |
| 10 |
// CHECK-NEXT: "file": "{{.+}}ftime-trace.cpp", |
| 11 |
// CHECK-NEXT: "line": {{[0-9]+}} |
| 12 |
// CHECK-NEXT: } |
| 13 |
|
| 14 |
// If any reports are found, "flushing" their equivalence class (EQC) is a separate action: |
| 15 |
// |
| 16 |
// CHECK: "name": "Flushing EQC Division by zero", |
| 17 |
// CHECK-NEXT: "args": { |
| 18 |
// CHECK-NEXT: "detail": "core.DivideZero", |
| 19 |
// CHECK-NEXT: "file": "{{.+}}ftime-trace.cpp", |
| 20 |
// CHECK-NEXT: "line": {{[0-9]+}} |
| 21 |
// CHECK-NEXT: } |
| 22 |
|
| 23 |
// The trace also contains durations of each step, but they are so short that they are not reliably present |
| 24 |
// in each run. However, they are also aggregated into Total *, for example: |
| 25 |
// |
| 26 |
// CHECK: "name": "Total dispatchWorkItem PostStmt", |
| 27 |
// CHECK-NEXT: "args": { |
| 28 |
// CHECK-NEXT: "count": {{[0-9]+}}, |
| 29 |
// CHECK-NEXT: "avg ms": {{[0-9]+}} |
| 30 |
// CHECK-NEXT: } |
| 31 |
|
| 32 |
// Additionally, the trace lists checker hook points (again, relying on totals here): |
| 33 |
// |
| 34 |
// CHECK: "name": "Total CheckerManager::runCheckersForStmt (Pre)", |
| 35 |
// CHECK-NEXT: "args": { |
| 36 |
// CHECK-NEXT: "count": {{[0-9]+}}, |
| 37 |
// CHECK-NEXT: "avg ms": {{[0-9]+}} |
| 38 |
// CHECK-NEXT: } |
| 39 |
|
| 40 |
// Finally, each checker call back is also present: |
| 41 |
// |
| 42 |
// CHECK: "name": "Total Stmt:DivZeroChecker", |
| 43 |
// CHECK-NEXT: "args": { |
| 44 |
// CHECK-NEXT: "count": {{[0-9]+}}, |
| 45 |
// CHECK-NEXT: "avg ms": {{[0-9]+}} |
| 46 |
// CHECK-NEXT: } |
| 47 |
|
| 48 |
bool coin(); |
| 49 |
int f() { |
| 50 |
int x = 0; |
| 51 |
int y = 0; |
| 52 |
while (coin()) { |
| 53 |
x = 1; |
| 54 |
} |
| 55 |
return x / y; // expected-warning{{Division by zero}} |
| 56 |
} |