1 | // RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,osx -analyzer-output=text -verify %s |
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 {{Assuming 'd' is equal to DBL_MAX}} |
34 | // expected-note@-1 {{Taking true branch}} |
35 | |
36 | char *p = NULL; // expected-note {{'p' initialized to a null pointer value}} |
37 | *p = 7; // expected-warning {{Dereference of null pointer (loaded from variable 'p')}} |
38 | // expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}} |
39 | } |
40 | } |
41 | |
42 | void testboolMacro(bool b, int *p) { |
43 | p = nullptr; // expected-note {{Null pointer value stored to 'p'}} |
44 | if (b == false) { // expected-note {{Assuming the condition is true}} |
45 | // expected-note@-1 {{Taking true branch}} |
46 | *p = 7; // expected-warning {{Dereference of null pointer (loaded from variable 'p')}} |
47 | // expected-note@-1 {{Dereference of null pointer (loaded from variable 'p')}} |
48 | } |
49 | } |
50 | |