Jordan Rose | b0e1bad | 2012-08-03 23:08:54 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-ipa=inlining -analyzer-output=text -verify %s |
| 2 | |
| 3 | void zero(int **p) { |
| 4 | *p = 0; |
| 5 | // expected-note@-1 {{Null pointer value stored to 'a'}} |
| 6 | } |
| 7 | |
| 8 | void 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 Rose | 6853799 | 2012-08-03 23:09:01 +0000 | [diff] [blame^] | 14 | } |
| 15 | |
| 16 | |
| 17 | void 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 | |
| 27 | void 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 | |
| 36 | int *getPointer(); |
| 37 | |
| 38 | void 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 | |
| 48 | void 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 | } |