]> granicus.if.org Git - clang/commitdiff
[analyzer] Run remove dead bindings before each call.
authorAnna Zaks <ganna@apple.com>
Fri, 24 Feb 2012 16:49:46 +0000 (16:49 +0000)
committerAnna Zaks <ganna@apple.com>
Fri, 24 Feb 2012 16:49:46 +0000 (16:49 +0000)
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

lib/StaticAnalyzer/Core/ExprEngine.cpp
test/Analysis/keychainAPI.m
test/Analysis/malloc-interprocedural.c

index a61c0272b532f9d14b629165c7a6fcf0cc7261bb..3cf07feadb6c54cd94e413c80fad961146a1f7f7 100644 (file)
@@ -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();
index c91982fef0dc4c45cae31d60a13e73410f72ee20..ce2ff206cfdbe25ee3c71173f45582b3863c9e2d 100644 (file)
@@ -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}}
   }
 }
 
index 0cdd9fb2810b91c4588b8a4f5c6f242ca32f4363..e67c14be426d8df504c87fb4fd7f46d21365ce70 100644 (file)
@@ -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)