blob: 8d7fccde1c618c638daab8f3e0c8c3ebcf8d59b4 [file] [log] [blame]
Dominic Chen4a90bf82017-03-02 22:58:06 +00001// RUN: %clang_cc1 -analyze -std=c++11 -analyzer-checker=core,osx -analyzer-output=text -verify %s
Anna Zaks40c74c62016-12-15 22:55:11 +00002
3#include "../Inputs/system-header-simulator.h"
4#include "../Inputs/system-header-simulator-cxx.h"
5
6void 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
15void 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
23void 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.
32void 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
41void 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}