diff options
author | Anna Zaks <ganna@apple.com> | 2012-02-24 16:49:46 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2012-02-24 16:49:46 +0000 |
commit | ff80afcfb2b00ccffcb6cb10528bec565fc59edd (patch) | |
tree | 7014b72743e520ce8163914dfff122759ad385aa | |
parent | e55b03a6e44b99c1cd77b8ea5e4d836c28948904 (diff) |
[analyzer] Run remove dead bindings before each call.
This ensures that we report the bugs associated with symbols going
out of scope in the correct function context.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151369 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/StaticAnalyzer/Core/ExprEngine.cpp | 6 | ||||
-rw-r--r-- | test/Analysis/keychainAPI.m | 4 | ||||
-rw-r--r-- | test/Analysis/malloc-interprocedural.c | 10 |
3 files changed, 17 insertions, 3 deletions
diff --git a/lib/StaticAnalyzer/Core/ExprEngine.cpp b/lib/StaticAnalyzer/Core/ExprEngine.cpp index a61c0272b5..3cf07feadb 100644 --- a/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -230,7 +230,11 @@ static bool shouldRemoveDeadBindings(AnalysisManager &AMgr, // Is this on a non-expression? if (!isa<Expr>(S.getStmt())) return true; - + + // Run before processing a call. + if (isa<CallExpr>(S.getStmt())) + return true; + // Is this an expression that is consumed by another expression? If so, // postpone cleaning out the state. ParentMap &PM = LC->getAnalysisDeclContext()->getParentMap(); diff --git a/test/Analysis/keychainAPI.m b/test/Analysis/keychainAPI.m index c91982fef0..ce2ff206cf 100644 --- a/test/Analysis/keychainAPI.m +++ b/test/Analysis/keychainAPI.m @@ -274,8 +274,8 @@ void DellocWithCFStringCreate2(CFAllocatorRef alloc) { char * x; st = SecKeychainItemCopyContent(2, ptr, ptr, &length, &bytes); if (st == noErr) { - CFStringRef userStr = CFStringCreateWithBytesNoCopy(alloc, bytes, length, 5, 0, kCFAllocatorNull); // expected-warning{{Allocated data is not released}} - CFRelease(userStr); + CFStringRef userStr = CFStringCreateWithBytesNoCopy(alloc, bytes, length, 5, 0, kCFAllocatorNull); + CFRelease(userStr); // expected-warning{{Allocated data is not released}} } } diff --git a/test/Analysis/malloc-interprocedural.c b/test/Analysis/malloc-interprocedural.c index 0cdd9fb281..e67c14be42 100644 --- a/test/Analysis/malloc-interprocedural.c +++ b/test/Analysis/malloc-interprocedural.c @@ -70,6 +70,16 @@ void test5() { my_free1((int*)data); } +static char *reshape(char *in) { + return 0; +} + +void testThatRemoveDeadBindingsRunBeforeEachCall() { + char *v = malloc(12); + v = reshape(v); + v = reshape(v);// expected-warning {{Memory is never released; potential memory leak}} +} + // Test that we keep processing after 'return;' void fooWithEmptyReturn(int x) { if (x) |