1 // RUN: %clang_cc1 -std=c++11 -Wno-conversion-null -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-store region -verify %s
3 void clang_analyzer_eval(int);
5 // test to see if nullptr is detected as a null pointer
8 *np = 0; // expected-warning{{Dereference of null pointer}}
11 // check if comparing nullptr to nullptr is detected properly
18 *np1 = 0; // no-warning
21 // invoving a nullptr in a more complex operation should be cause a warning
27 // casting a nullptr to anything should be caught eventually
28 int *ip = &(((struct foo *)np)->f);
29 *ip = 0; // expected-warning{{Dereference of null pointer}}
30 // should be error here too, but analysis gets stopped
34 // nullptr is implemented as a zero integer value, so should be able to compare
38 *np = 0; // no-warning
41 *np = 0; // no-warning
44 int pr10372(void *& x) {
45 // GNU null is a pointer-sized integer, not a pointer.
47 // This used to crash.
53 delete *(p + 0); // expected-warning{{Dereference of null pointer}}
61 :"0"(*b) // expected-warning{{Dereference of null pointer}}
65 int exprWithCleanups() {
74 return S(*x).a; // expected-warning{{Dereference of null pointer}}
77 int materializeTempExpr() {
83 const S &s = S(*n); // expected-warning{{Dereference of null pointer}}
87 typedef decltype(nullptr) nullptr_t;
88 void testMaterializeTemporaryExprWithNullPtr() {
89 // Create MaterializeTemporaryExpr with a nullptr inside.
90 const nullptr_t &r = nullptr;
100 x->f(); // expected-warning{{Called C++ object pointer is null}}
107 void shouldNotCrash() {
110 invokeF(p); // expected-warning{{Function call argument is an uninit}}
115 x->f(); // expected-warning{{Called C++ object pointer is null}}
119 void f(decltype(nullptr) p) {
121 clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
122 clang_analyzer_eval(q == 0); // expected-warning{{TRUE}}
125 decltype(nullptr) returnsNullPtrType();
126 void fromReturnType() {
127 ((X *)returnsNullPtrType())->f(); // expected-warning{{Called C++ object pointer is null}}