1 // RUN: %clang_analyze_cc1 \ 2 // RUN: -analyzer-checker=core,debug.ExprInspection \ 3 // RUN: -verify %s 4 5 void clang_analyzer_eval(bool); 6 void clang_analyzer_warnIfReached(); 7 8 typedef __typeof__(sizeof(int)) size_t; 9 10 void *operator new(size_t size) throw() { 11 return nullptr; 12 } 13 void *operator new[](size_t size) throw() { 14 return nullptr; 15 } 16 17 struct S { 18 int x; 19 S() : x(1) { 20 // FIXME: Constructor should not be called with null this, even if it was 21 // returned by operator new(). 22 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} 23 } 24 ~S() {} 25 }; 26 27 void testArrays() { 28 S *s = new S[10]; // no-crash 29 s[0].x = 2; 30 // no-warning: 'Dereference of null pointer' suppressed by ReturnVisitor. 31 } 32 33 int global; 34 void testInvalidationOnConstructionIntoNull() { 35 global = 0; 36 S *s = new S(); 37 // FIXME: Should be FALSE - we should not invalidate globals. 38 clang_analyzer_eval(global); // expected-warning{{UNKNOWN}} 39 } 40