1 // RUN: %clang_cc1 -analyze -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 {{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 }
49