summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis/NewDelete-custom.cpp
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2013-04-05 17:55:00 +0000
committerJordan Rose <jordan_rose@apple.com>2013-04-05 17:55:00 +0000
commit26330563f27a93b9c0a0639a3e4f4cf538aa54fe (patch)
treef5afb0f99fb33432db351cbde492751555406ea7 /clang/test/Analysis/NewDelete-custom.cpp
parent0b55b438b25d39c37737282030d4d9d8bee07fc9 (diff)
downloadbcm5719-llvm-26330563f27a93b9c0a0639a3e4f4cf538aa54fe.tar.gz
bcm5719-llvm-26330563f27a93b9c0a0639a3e4f4cf538aa54fe.zip
[analyzer] Split new/delete checker into use-after-free and leaks parts.
This splits the leak-checking part of alpha.cplusplus.NewDelete into a separate user-level checker, alpha.cplusplus.NewDeleteLeaks. All the difficult false positives we've seen with the new/delete checker have been spurious leak warnings; the use-after-free warnings and mismatched deallocator warnings, while rare, have always been valid. <rdar://problem/6194569> llvm-svn: 178890
Diffstat (limited to 'clang/test/Analysis/NewDelete-custom.cpp')
-rw-r--r--clang/test/Analysis/NewDelete-custom.cpp35
1 files changed, 29 insertions, 6 deletions
diff --git a/clang/test/Analysis/NewDelete-custom.cpp b/clang/test/Analysis/NewDelete-custom.cpp
index 7d7796bccb6..a4665a17577 100644
--- a/clang/test/Analysis/NewDelete-custom.cpp
+++ b/clang/test/Analysis/NewDelete-custom.cpp
@@ -1,6 +1,12 @@
-// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.cplusplus.NewDelete,unix.Malloc -analyzer-store region -std=c++11 -fblocks -verify %s
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.cplusplus.NewDelete,unix.Malloc -std=c++11 -fblocks -verify %s
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.cplusplus.NewDelete,alpha.cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -DLEAKS -fblocks -verify %s
#include "Inputs/system-header-simulator-cxx.h"
+#ifndef LEAKS
+// expected-no-diagnostics
+#endif
+
+
void *allocator(std::size_t size);
void *operator new[](std::size_t size) throw() { return allocator(size); }
@@ -19,7 +25,10 @@ void testNewMethod() {
C *p2 = new C; // no warn
C *c3 = ::new C;
-} // expected-warning{{Memory is never released; potential leak}}
+}
+#ifdef LEAKS
+// expected-warning@-2{{Memory is never released; potential leak}}
+#endif
void testOpNewArray() {
void *p = operator new[](0); // call is inlined, no warn
@@ -27,7 +36,11 @@ void testOpNewArray() {
void testNewExprArray() {
int *p = new int[0];
-} // expected-warning{{Memory is never released; potential leak}}
+}
+#ifdef LEAKS
+// expected-warning@-2{{Memory is never released; potential leak}}
+#endif
+
//----- Custom non-placement operators
void testOpNew() {
@@ -36,16 +49,26 @@ void testOpNew() {
void testNewExpr() {
int *p = new int;
-} // expected-warning{{Memory is never released; potential leak}}
+}
+#ifdef LEAKS
+// expected-warning@-2{{Memory is never released; potential leak}}
+#endif
+
//----- Custom NoThrow placement operators
void testOpNewNoThrow() {
void *p = operator new(0, std::nothrow);
-} // expected-warning{{Memory is never released; potential leak}}
+}
+#ifdef LEAKS
+// expected-warning@-2{{Memory is never released; potential leak}}
+#endif
void testNewExprNoThrow() {
int *p = new(std::nothrow) int;
-} // expected-warning{{Memory is never released; potential leak}}
+}
+#ifdef LEAKS
+// expected-warning@-2{{Memory is never released; potential leak}}
+#endif
//----- Custom placement operators
void testOpNewPlacement() {
OpenPOWER on IntegriCloud