Dominic Chen | 4a90bf8 | 2017-03-02 22:58:06 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -analyze -std=c++11 -analyzer-checker=core,osx -analyzer-output=text -verify %s |
Anna Zaks | 40c74c6 | 2016-12-15 22:55:11 +0000 | [diff] [blame] | 2 | |
| 3 | #include "../Inputs/system-header-simulator.h" |
| 4 | #include "../Inputs/system-header-simulator-cxx.h" |
| 5 | |
| 6 | void testIntMacro(unsigned int i) { |
| 7 | if (i == UINT32_MAX) { // expected-note {{Assuming 'i' is equal to UINT32_MAX}} |
| 8 | // expected-note@-1 {{Taking true branch}} |
| 9 | char *p = NULL; // expected-note {{'p' initialized to a null pointer value}} |
| 10 | *p = 7; // expected-warning {{Dereference of null pointer (loaded from variable 'p')}} |
| 11 | // expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}} |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | void testNULLMacro(int *p) { |
| 16 | if (p == NULL) { // expected-note {{Assuming 'p' is equal to NULL}} |
| 17 | // expected-note@-1 {{Taking true branch}} |
| 18 | *p = 7; // expected-warning {{Dereference of null pointer (loaded from variable 'p')}} |
| 19 | // expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}} |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | void testnullptrMacro(int *p) { |
| 24 | if (p == nullptr) { // expected-note {{Assuming pointer value is null}} |
| 25 | // expected-note@-1 {{Taking true branch}} |
| 26 | *p = 7; // expected-warning {{Dereference of null pointer (loaded from variable 'p')}} |
| 27 | // expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}} |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | // There are no path notes on the comparison to float types. |
| 32 | void testDoubleMacro(double d) { |
| 33 | if (d == DBL_MAX) { // expected-note {{Taking true branch}} |
| 34 | |
| 35 | char *p = NULL; // expected-note {{'p' initialized to a null pointer value}} |
| 36 | *p = 7; // expected-warning {{Dereference of null pointer (loaded from variable 'p')}} |
| 37 | // expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}} |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | void testboolMacro(bool b, int *p) { |
| 42 | p = nullptr; // expected-note {{Null pointer value stored to 'p'}} |
| 43 | if (b == false) { // expected-note {{Assuming the condition is true}} |
| 44 | // expected-note@-1 {{Taking true branch}} |
| 45 | *p = 7; // expected-warning {{Dereference of null pointer (loaded from variable 'p')}} |
| 46 | // expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}} |
| 47 | } |
| 48 | } |