1 // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -analyzer-config graph-trim-interval=5 -verify %s
2 // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=plist-multi-file -analyzer-config graph-trim-interval=5 %s -o %t.plist
3 // RUN: %normalize_plist <%t.plist | diff -ub %S/Inputs/expected-plists/eager-reclamation-path-notes.c.plist -
4
use(int * ptr,int val)5 void use(int *ptr, int val) {
6 *ptr = val; // expected-warning {{Dereference of null pointer (loaded from variable 'ptr')}}
7 // expected-note@-1 {{Dereference of null pointer (loaded from variable 'ptr')}}
8 }
9
compute()10 int compute() {
11 // Do something that will take enough processing to trigger trimming.
12 // FIXME: This is actually really sensitive. If the interval timing is just
13 // wrong, the node for the actual dereference may also be collected, and all
14 // the path notes will disappear. <rdar://problem/12511814>
15 return 2 + 3 + 4 + 5 + 6;
16 }
17
testSimple()18 void testSimple() {
19 int *p = 0;
20 // expected-note@-1 {{'p' initialized to a null pointer value}}
21 use(p, compute());
22 // expected-note@-1 {{Passing null pointer value via 1st parameter 'ptr'}}
23 // expected-note@-2 {{Calling 'use'}}
24 }
25
26
use2(int * ptr,int val)27 void use2(int *ptr, int val) {
28 *ptr = val; // expected-warning {{Dereference of null pointer (loaded from variable 'ptr')}}
29 // expected-note@-1 {{Dereference of null pointer (loaded from variable 'ptr')}}
30 }
31
passThrough(int * p)32 void passThrough(int *p) {
33 use2(p, compute());
34 // expected-note@-1 {{Passing null pointer value via 1st parameter 'ptr'}}
35 // expected-note@-2 {{Calling 'use2'}}
36 }
37
testChainedCalls()38 void testChainedCalls() {
39 int *ptr = 0;
40 // expected-note@-1 {{'ptr' initialized to a null pointer value}}
41 passThrough(ptr);
42 // expected-note@-1 {{Passing null pointer value via 1st parameter 'p'}}
43 // expected-note@-2 {{Calling 'passThrough'}}
44 }
45
46