1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify -analyzer-config eagerly-assume=false %s 2 3 void clang_analyzer_eval(bool); 4 5 typedef __typeof__(sizeof(int)) size_t; 6 7 void *conjure(); 8 void exit(int); 9 operator new(size_t size)10void *operator new(size_t size) throw() { 11 void *x = conjure(); 12 if (x == 0) 13 exit(1); 14 return x; 15 } 16 17 struct S { 18 int x; SS19 S() : x(1) {} ~SS20 ~S() {} 21 }; 22 checkNewAndConstructorInlining()23void checkNewAndConstructorInlining() { 24 S *s = new S; 25 // Check that the symbol for 's' is not dying. 26 clang_analyzer_eval(s != 0); // expected-warning{{TRUE}} 27 // Check that bindings are correct (and also not dying). 28 clang_analyzer_eval(s->x == 1); // expected-warning{{TRUE}} 29 } 30 31 struct Sp { 32 Sp *p; SpSp33 Sp(Sp *p): p(p) {} ~SpSp34 ~Sp() {} 35 }; 36 checkNestedNew()37void checkNestedNew() { 38 Sp *p = new Sp(new Sp(0)); 39 clang_analyzer_eval(p->p->p == 0); // expected-warning{{TRUE}} 40 } 41 checkNewPOD()42void checkNewPOD() { 43 int *i = new int; 44 clang_analyzer_eval(*i == 0); // expected-warning{{UNKNOWN}} 45 int *j = new int(); 46 clang_analyzer_eval(*j == 0); // expected-warning{{TRUE}} 47 int *k = new int(5); 48 clang_analyzer_eval(*k == 5); // expected-warning{{TRUE}} 49 } 50 checkTrivialCopy()51void checkTrivialCopy() { 52 S s; 53 S *t = new S(s); // no-crash 54 clang_analyzer_eval(t->x == 1); // expected-warning{{TRUE}} 55 } 56