George Karpenkov | a393e68 | 2018-08-29 20:29:17 +0000 | [diff] [blame] | 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 |
Artem Dergachev | 5579630 | 2018-01-17 22:34:23 +0000 | [diff] [blame] | 2 | |
| 3 | void clang_analyzer_eval(bool); |
| 4 | |
| 5 | typedef __typeof__(sizeof(int)) size_t; |
| 6 | |
| 7 | void *conjure(); |
| 8 | void exit(int); |
| 9 | |
| 10 | void *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; |
| 19 | S() : x(1) {} |
| 20 | ~S() {} |
| 21 | }; |
| 22 | |
| 23 | void 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; |
| 33 | Sp(Sp *p): p(p) {} |
| 34 | ~Sp() {} |
| 35 | }; |
| 36 | |
| 37 | void checkNestedNew() { |
| 38 | Sp *p = new Sp(new Sp(0)); |
| 39 | clang_analyzer_eval(p->p->p == 0); // expected-warning{{TRUE}} |
| 40 | } |
Artem Dergachev | beba530 | 2018-01-17 22:51:19 +0000 | [diff] [blame] | 41 | |
| 42 | void 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 | |
| 51 | void checkTrivialCopy() { |
| 52 | S s; |
| 53 | S *t = new S(s); // no-crash |
| 54 | clang_analyzer_eval(t->x == 1); // expected-warning{{TRUE}} |
| 55 | } |