blob: 53bc4249b7fd6a1690dd6a24c1457c250bdf03f7 [file] [log] [blame]
Jordan Roseb0e1bad2012-08-03 23:08:54 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-ipa=inlining -analyzer-output=text -verify %s
2
3void zero(int **p) {
4 *p = 0;
5 // expected-note@-1 {{Null pointer value stored to 'a'}}
6}
7
8void testZero(int *a) {
9 zero(&a);
10 // expected-note@-1 {{Calling 'zero'}}
11 // expected-note@-2 {{Returning from 'zero'}}
12 *a = 1; // expected-warning{{Dereference of null pointer}}
13 // expected-note@-1 {{Dereference of null pointer (loaded from variable 'a')}}
Jordan Rose68537992012-08-03 23:09:01 +000014}
15
16
17void check(int *p) {
18 if (p) {
19 // expected-note@-1 + {{Assuming 'p' is null}}
20 // expected-note@-2 + {{Assuming pointer value is null}}
21 // expected-note@-3 + {{Taking false branch}}
22 return;
23 }
24 return;
25}
26
27void testCheck(int *a) {
28 check(a);
29 // expected-note@-1 {{Calling 'check'}}
30 // expected-note@-2 {{Returning from 'check'}}
31 *a = 1; // expected-warning{{Dereference of null pointer}}
32 // expected-note@-1 {{Dereference of null pointer (loaded from variable 'a')}}
33}
34
35
36int *getPointer();
37
38void testInitCheck() {
39 int *a = getPointer();
40 // expected-note@-1 {{Variable 'a' initialized here}}
41 check(a);
42 // expected-note@-1 {{Calling 'check'}}
43 // expected-note@-2 {{Returning from 'check'}}
44 *a = 1; // expected-warning{{Dereference of null pointer}}
45 // expected-note@-1 {{Dereference of null pointer (loaded from variable 'a')}}
46}
47
48void testStoreCheck(int *a) {
49 a = getPointer();
50 // expected-note@-1 {{Value assigned to 'a'}}
51 check(a);
52 // expected-note@-1 {{Calling 'check'}}
53 // expected-note@-2 {{Returning from 'check'}}
54 *a = 1; // expected-warning{{Dereference of null pointer}}
55 // expected-note@-1 {{Dereference of null pointer (loaded from variable 'a')}}
56}