aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Yartsev <anton.yartsev@gmail.com>2013-04-12 20:48:49 +0000
committerAnton Yartsev <anton.yartsev@gmail.com>2013-04-12 20:48:49 +0000
commitb1b683ea5f1ff161b6bbdf2e2519317618ee2811 (patch)
tree6eab4cd0bdde9058a2ddd83b388dc13b903e3f29
parent1e8058f8d90fab1b9011adf62caa52e19e61382c (diff)
[analyzer] Makes NewDeleteLeaks checker work independently from NewDelete.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179410 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/StaticAnalyzer/Checkers/MallocChecker.cpp2
-rw-r--r--test/Analysis/NewDeleteLeaks-checker-test.cpp28
2 files changed, 29 insertions, 1 deletions
diff --git a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index e19e3f72c7..246dc1588b 100644
--- a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -1091,7 +1091,7 @@ bool MallocChecker::isTrackedByCurrentChecker(AllocationFamily Family) const {
}
case AF_CXXNew:
case AF_CXXNewArray: {
- if (!Filter.CNewDeleteChecker)
+ if (!Filter.CNewDeleteChecker && !Filter.CNewDeleteLeaksChecker)
return false;
return true;
}
diff --git a/test/Analysis/NewDeleteLeaks-checker-test.cpp b/test/Analysis/NewDeleteLeaks-checker-test.cpp
new file mode 100644
index 0000000000..93707ec190
--- /dev/null
+++ b/test/Analysis/NewDeleteLeaks-checker-test.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.cplusplus.NewDeleteLeaks -std=c++11 -fblocks -verify %s
+#include "Inputs/system-header-simulator-cxx.h"
+
+//----- Standard non-placement operators
+void testGlobalOpNew() {
+ void *p = operator new(0);
+} // expected-warning{{Potential leak of memory pointed to by 'p'}}
+
+void testGlobalOpNewArray() {
+ void *p = operator new[](0);
+} // expected-warning{{Potential leak of memory pointed to by 'p'}}
+
+void testGlobalNewExpr() {
+ int *p = new int;
+} // expected-warning{{Potential leak of memory pointed to by 'p'}}
+
+void testGlobalNewExprArray() {
+ int *p = new int[0];
+} // expected-warning{{Potential leak of memory pointed to by 'p'}}
+
+//----- Standard nothrow placement operators
+void testGlobalNoThrowPlacementOpNewBeforeOverload() {
+ void *p = operator new(0, std::nothrow);
+} // expected-warning{{Potential leak of memory pointed to by 'p'}}
+
+void testGlobalNoThrowPlacementExprNewBeforeOverload() {
+ int *p = new(std::nothrow) int;
+} // expected-warning{{Potential leak of memory pointed to by 'p'}}