[cfe-commits] r158532 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp test/Analysis/delegates.m

Jordan Rose jordan_rose at apple.com
Fri Jun 15 11:19:52 PDT 2012


Author: jrose
Date: Fri Jun 15 13:19:52 2012
New Revision: 158532

URL: http://llvm.org/viewvc/llvm-project?rev=158532&view=rev
Log:
[analyzer] RetainCount: don't track objects init'd with a delegate

We already didn't track objects that have delegates or callbacks or
objects that are passed through void * "context pointers". It's a
not-uncommon pattern to release the object in its callback, and so
the leak message we give is not very helpful.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
    cfe/trunk/test/Analysis/delegates.m

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp?rev=158532&r1=158531&r2=158532&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp Fri Jun 15 13:19:52 2012
@@ -1351,10 +1351,15 @@
   // because the reference count is quite possibly handled by a delegate
   // method.
   if (S.isKeywordSelector()) {
-    const std::string &str = S.getAsString();
-    assert(!str.empty());
-    if (StrInStrNoCase(str, "delegate:") != StringRef::npos)
-      ReceiverEff = StopTracking;
+    for (unsigned i = 0, e = S.getNumArgs(); i != e; ++i) {
+      StringRef Slot = S.getNameForSlot(i);
+      if (Slot.substr(Slot.size() - 8).equals_lower("delegate")) {
+        if (ResultEff == ObjCInitRetE)
+          ResultEff = RetEffect::MakeNoRet();
+        else
+          ReceiverEff = StopTracking;
+      }
+    }
   }
 
   if (ScratchArgs.isEmpty() && ReceiverEff == DoNothing &&

Modified: cfe/trunk/test/Analysis/delegates.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/delegates.m?rev=158532&r1=158531&r2=158532&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/delegates.m (original)
+++ cfe/trunk/test/Analysis/delegates.m Fri Jun 15 13:19:52 2012
@@ -111,3 +111,21 @@
 }
 @end
 
+
+ at interface ObjectThatRequiresDelegate : NSObject
+- (id)initWithDelegate:(id)delegate;
+- (id)initWithNumber:(int)num delegate:(id)delegate;
+ at end
+
+
+ at interface DelegateRequirerTest
+ at end
+ at implementation DelegateRequirerTest
+
+- (void)test {
+  (void)[[ObjectThatRequiresDelegate alloc] initWithDelegate:self];
+  (void)[[ObjectThatRequiresDelegate alloc] initWithNumber:0 delegate:self];
+  // no leak warnings -- these objects could be released in callback methods
+}
+
+ at end





More information about the cfe-commits mailing list