diff options
Diffstat (limited to 'test/Analysis/new.cpp')
-rw-r--r-- | test/Analysis/new.cpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/test/Analysis/new.cpp b/test/Analysis/new.cpp index 6cfcb1d927195..31f763266c381 100644 --- a/test/Analysis/new.cpp +++ b/test/Analysis/new.cpp @@ -1,4 +1,5 @@ // RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-store region -std=c++11 -verify %s +// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-store region -std=c++11 -DTEST_INLINABLE_ALLOCATORS -verify %s #include "Inputs/system-header-simulator-cxx.h" void clang_analyzer_eval(bool); @@ -34,7 +35,7 @@ void *testPlacementNew() { void *y = new (x) int; clang_analyzer_eval(x == y); // expected-warning{{TRUE}}; - clang_analyzer_eval(*x == 1); // expected-warning{{UNKNOWN}}; + clang_analyzer_eval(*x == 1); // expected-warning{{TRUE}}; return y; } @@ -137,7 +138,7 @@ void testNewDeleteNoWarn() { // unix.Malloc does not know about operators new/delete. void testDeleteMallocked() { int *x = (int *)malloc(sizeof(int)); - delete x; // FIXME: Shoud detect pointer escape and keep silent after 'delete' is modeled properly. + delete x; // FIXME: Should detect pointer escape and keep silent after 'delete' is modeled properly. } // expected-warning{{Potential leak of memory pointed to by 'x'}} void testDeleteOpAfterFree() { @@ -200,8 +201,7 @@ int testNoInitializationPlacement() { int n; new (&n) int; - // Should warn that n is uninitialized. - if (n) { // no-warning + if (n) { // expected-warning{{Branch condition evaluates to a garbage value}} return 0; } return 1; @@ -274,6 +274,24 @@ void test_var_delete() { clang_analyzer_eval(true); // expected-warning{{TRUE}} } +void test_array_delete() { + class C { + public: + ~C() {} + }; + + auto c1 = new C[2][3]; + delete[] c1; // no-crash // no-warning + + C c2[4]; + // FIXME: Should warn. + delete[] &c2; // no-crash + + C c3[7][6]; + // FIXME: Should warn. + delete[] &c3; // no-crash +} + void testDeleteNull() { NoReturnDtor *foo = 0; delete foo; // should not call destructor, checked below @@ -311,7 +329,7 @@ void testArrayNull() { void testArrayDestr() { NoReturnDtor *p = new NoReturnDtor[2]; delete[] p; // Calls the base destructor which aborts, checked below - //TODO: clang_analyzer_eval should not be called + //TODO: clang_analyzer_eval should not be called clang_analyzer_eval(true); // expected-warning{{TRUE}} } |