diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-09-05 22:55:23 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-09-05 22:55:23 +0000 |
commit | 6d671cc34a221c62a011bb4717526388fc7aa4cb (patch) | |
tree | 6b82aea007c1748d0e2c240aa17dd6bfa25a9729 /clang/test/Analysis/malloc.cpp | |
parent | e53314f7e3b43dbea77db9dc324b410e01c9db8f (diff) | |
download | bcm5719-llvm-6d671cc34a221c62a011bb4717526388fc7aa4cb.tar.gz bcm5719-llvm-6d671cc34a221c62a011bb4717526388fc7aa4cb.zip |
[analyzer] Always include destructors in the analysis CFG.
While destructors will continue to not be inlined (unless the analyzer
config option 'c++-inlining' is set to 'destructors'), leaving them out
of the CFG is an incomplete model of the behavior of an object, and
can cause false positive warnings (like PR13751, now working).
Destructors for temporaries are still not on by default, since
(a) we haven't actually checked this code to be sure it's fully correct
(in particular, we probably need to be very careful with regard to
lifetime-extension when a temporary is bound to a reference,
C++11 [class.temporary]p5), and
(b) ExprEngine doesn't actually do anything when it sees a temporary
destructor in the CFG -- not even invalidate the object region.
To enable temporary destructors, set the 'cfg-temporary-dtors' analyzer
config option to '1'. The old -cfg-add-implicit-dtors cc1 option, which
controlled all implicit destructors, has been removed.
llvm-svn: 163264
Diffstat (limited to 'clang/test/Analysis/malloc.cpp')
-rw-r--r-- | clang/test/Analysis/malloc.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/test/Analysis/malloc.cpp b/clang/test/Analysis/malloc.cpp index 864477b587b..220d74625bc 100644 --- a/clang/test/Analysis/malloc.cpp +++ b/clang/test/Analysis/malloc.cpp @@ -6,6 +6,11 @@ void free(void *); void *realloc(void *ptr, size_t size); void *calloc(size_t nmemb, size_t size); + +void checkThatMallocCheckerIsRunning() { + malloc(4); // expected-warning{{leak}} +} + // Test for radar://11110132. struct Foo { mutable void* m_data; @@ -35,3 +40,23 @@ void r11160612_3(CanFreeMemory* p) { const_ptr_and_callback_def_param(0, x, 12, p->myFree); } + +namespace PR13751 { + class OwningVector { + void **storage; + size_t length; + public: + OwningVector(); + ~OwningVector(); + void push_back(void *Item) { + storage[length++] = Item; + } + }; + + void testDestructors() { + OwningVector v; + v.push_back(malloc(4)); + // no leak warning; freed in destructor + } +} + |