]> granicus.if.org Git - clang/commitdiff
[analyzer]RetainCount: Fix an autorelease related false positive.
authorAnna Zaks <ganna@apple.com>
Thu, 31 Jan 2013 22:36:17 +0000 (22:36 +0000)
committerAnna Zaks <ganna@apple.com>
Thu, 31 Jan 2013 22:36:17 +0000 (22:36 +0000)
The Cnt variable is adjusted (incremented) for simplification of
checking logic. The increment should not be stored in the state.

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

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

index e731e034d8524735fa5391e92e68e41174944ea5..533d0b8420082069af065418ca1e9e7e604781c3 100644 (file)
@@ -3487,7 +3487,7 @@ RetainCountChecker::handleAutoreleaseCounts(ProgramStateRef state,
       else
         V = V ^ RefVal::NotOwned;
     } else {
-      V.setCount(Cnt - ACnt);
+      V.setCount(V.getCount() - ACnt);
       V.setAutoreleaseCount(0);
     }
     return setRefBinding(state, Sym, V);
index 44332d2451b41c003999179e69de2505910b53b9..9de6cedaf05c25925a50b49d9f9449f06cef3916 100644 (file)
@@ -1784,6 +1784,13 @@ extern id NSApp;
       id contextObject = (id)contextInfo;
       [contextObject release];
 }
+
+- (id)copyAutoreleaseRadar13081402 {
+  id x = [[[NSString alloc] initWithUTF8String:"foo"] autorelease];
+  [x retain];
+  return x; // no warning
+}
+
 @end
 //===----------------------------------------------------------------------===//
 // Test returning allocated memory in a struct.
@@ -1961,6 +1968,7 @@ void test_drain() {
 }
 
 
+
 // CHECK:  <key>diagnostics</key>
 // CHECK-NEXT:  <array>
 // CHECK-NEXT:   <dict>