[analyzer] Switched to checkPreCall interface for detecting usage after free.
Now the check is also applied to arguments for Objective-C method calls and to 'this' pointer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179230 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Analysis/new.cpp b/test/Analysis/new.cpp
index 8022430..8d3eee9 100644
--- a/test/Analysis/new.cpp
+++ b/test/Analysis/new.cpp
@@ -8,6 +8,12 @@
extern "C" void free(void *);
int someGlobal;
+
+class SomeClass {
+public:
+ void f(int *p);
+};
+
void testImplicitlyDeclaredGlobalNew() {
if (someGlobal != 0)
return;
@@ -101,6 +107,12 @@
new (&w.x) (int*)(0); // we cache out here; don't crash
}
+void testUseAfter(int *p) {
+ SomeClass *c = new SomeClass;
+ free(p);
+ c->f(p); // expected-warning{{Use of memory after it is freed}}
+ delete c;
+}
//--------------------------------------------------------------------
// Check for intersection with other checkers from MallocChecker.cpp
@@ -152,6 +164,12 @@
p = new(0, p) int; // expected-warning{{Use of memory after it is freed}}
}
+void testUsingThisAfterDelete() {
+ SomeClass *c = new SomeClass;
+ delete c;
+ c->f(0); // no-warning
+}
+
//--------------------------------
// Incorrectly-modelled behavior
//--------------------------------