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