diff options
author | dim <dim@FreeBSD.org> | 2013-06-10 20:45:12 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2013-06-10 20:45:12 +0000 |
commit | ea266cad53e3d49771fa38103913d3ec7a166694 (patch) | |
tree | 8f7776b7310bebaf415ac5b69e46e9f928c37144 /test/Analysis/new.cpp | |
parent | c72c57c9e9b69944e3e009cd5e209634839581d3 (diff) | |
download | FreeBSD-src-ea266cad53e3d49771fa38103913d3ec7a166694.zip FreeBSD-src-ea266cad53e3d49771fa38103913d3ec7a166694.tar.gz |
Vendor import of clang tags/RELEASE_33/final r183502 (effectively, 3.3
release):
http://llvm.org/svn/llvm-project/cfe/tags/RELEASE_33/final@183502
Diffstat (limited to 'test/Analysis/new.cpp')
-rw-r--r-- | test/Analysis/new.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/test/Analysis/new.cpp b/test/Analysis/new.cpp index 44ae980..8d3eee9 100644 --- a/test/Analysis/new.cpp +++ b/test/Analysis/new.cpp @@ -8,6 +8,12 @@ extern "C" void *malloc(size_t); extern "C" void free(void *); int someGlobal; + +class SomeClass { +public: + void f(int *p); +}; + void testImplicitlyDeclaredGlobalNew() { if (someGlobal != 0) return; @@ -101,6 +107,12 @@ void testCacheOut(PtrWrapper w) { 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 @@ -126,7 +138,7 @@ void testNewDeleteNoWarn() { void testDeleteMallocked() { int *x = (int *)malloc(sizeof(int)); delete x; // FIXME: Shoud detect pointer escape and keep silent after 'delete' is modeled properly. -} // expected-warning{{Memory is never released; potential leak}} +} // expected-warning{{Potential leak of memory pointed to by 'x'}} void testDeleteOpAfterFree() { int *p = (int *)malloc(sizeof(int)); @@ -152,6 +164,12 @@ void testCustomPlacementNewAfterFree() { 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 //-------------------------------- |