]> granicus.if.org Git - clang/commitdiff
[analyzer] RetainRelease: Self assignment should not suppress a leak
authorAnna Zaks <ganna@apple.com>
Wed, 2 May 2012 00:15:40 +0000 (00:15 +0000)
committerAnna Zaks <ganna@apple.com>
Wed, 2 May 2012 00:15:40 +0000 (00:15 +0000)
warning.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155966 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
test/Analysis/retain-release.m

index 2a97e1c24a72a07add17c94008e7782df25c7c06..3bd7ae432243165e972e3aea84ebcfbd38acd539 100644 (file)
@@ -3347,7 +3347,11 @@ void RetainCountChecker::checkBind(SVal loc, SVal val, const Stmt *S,
       // To test (3), generate a new state with the binding added.  If it is
       // the same state, then it escapes (since the store cannot represent
       // the binding).
-      escapes = (state == (state->bindLoc(*regionLoc, val)));
+      // Do this only if we know that the store is not supposed to generate the
+      // same state.
+      SVal StoredVal = state->getSVal(regionLoc->getRegion());
+      if (StoredVal != val)
+        escapes = (state == (state->bindLoc(*regionLoc, val)));
     }
     if (!escapes) {
       // Case 4: We do not currently model what happens when a symbol is
index 3aa2656c62f44e69a8b08d6efa641bd2f2b678e2..54af13d2a34dc52ca379cbdeeab401a5d8e333c0 100644 (file)
@@ -1305,6 +1305,11 @@ void testattr2_b() {
   TestOwnershipAttr *x = [[TestOwnershipAttr alloc] pseudoInit];  // expected-warning{{leak}}
 }
 
+void testattr2_b_11358224_self_assign_looses_the_leak() {
+  TestOwnershipAttr *x = [[TestOwnershipAttr alloc] pseudoInit];// expected-warning{{leak}}
+  x = x;
+}
+
 void testattr2_c() {
   TestOwnershipAttr *x = [[TestOwnershipAttr alloc] pseudoInit]; // no-warning
   [x release];