xref: /llvm-project/clang/test/Analysis/html_diagnostics/counter.c (revision 243bfed68367263cfc3fb3f396660acf60051fbf)
1 // RUN: rm -fR %t
2 // RUN: mkdir %t
3 // RUN: %clang_analyze_cc1 -analyzer-checker=core \
4 // RUN:                    -analyzer-output=html -o %t -verify %s
5 // RUN: grep -v CHECK %t/report-*.html | FileCheck %s
6 
7 
foo()8 void foo() {
9   int *x = 0;
10   *x = __COUNTER__; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}
11 }
12 
bar()13 void bar() {
14   int *y;
15   *y = __COUNTER__; // expected-warning{{Dereference of undefined pointer value (loaded from variable 'y')}}
16 }
17 
18 // The checks below confirm that both reports have the same values for __COUNTER__.
19 //
20 // FIXME: The correct values are (0, 1, 0, 1). Because we re-lex the file in order
21 // to detect macro expansions for HTML report purposes, they turn into (2, 3, 2, 3)
22 // by the time we emit HTML. But at least it's better than (2, 3, 4, 5)
23 // which would have been the case if we re-lexed the file *each* time we
24 // emitted an HTML report.
25 
26 // CHECK: <span class='macro'>__COUNTER__<span class='macro_popup'>2</span></span>
27 // CHECK: <span class='macro'>__COUNTER__<span class='macro_popup'>3</span></span>
28 // CHECK: <span class='macro'>__COUNTER__<span class='macro_popup'>2</span></span>
29 // CHECK: <span class='macro'>__COUNTER__<span class='macro_popup'>3</span></span>
30