[cfe-commits] r69984 - /cfe/trunk/lib/Analysis/CFRefCount.cpp

Ted Kremenek kremenek at apple.com
Fri Apr 24 11:00:34 PDT 2009


Author: kremenek
Date: Fri Apr 24 13:00:17 2009
New Revision: 69984

URL: http://llvm.org/viewvc/llvm-project?rev=69984&view=rev
Log:
retain/release checker: more hacks to workaround false positives cause by
delegates. When a reference counted object is passed as to a 'void*' argument to
a method stop tracking the reference count.

Modified:
    cfe/trunk/lib/Analysis/CFRefCount.cpp

Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=69984&r1=69983&r2=69984&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Fri Apr 24 13:00:17 2009
@@ -1076,9 +1076,28 @@
 RetainSummary*
 RetainSummaryManager::getCommonMethodSummary(ObjCMessageExpr* ME, const char *s)
 {
+  if (ObjCMethodDecl *MD = ME->getMethodDecl()) {
+    // Scan the method decl for 'void*' arguments.  These should be treated
+    // as 'StopTracking' because they are often used with delegates.
+    // Delegates are a frequent form of false positives with the retain
+    // count checker.
+    unsigned i = 0;
+    for (ObjCMethodDecl::param_iterator I = MD->param_begin(),
+         E = MD->param_end(); I != E; ++I, ++i)
+      if (ParmVarDecl *PD = *I) {
+        QualType Ty = Ctx.getCanonicalType(PD->getType());
+        if (Ty.getUnqualifiedType() == Ctx.VoidPtrTy)
+          ScratchArgs.push_back(std::make_pair(i, StopTracking));
+      }
+  }
+  
   // Look for methods that return an owned object.
-  if (!isTrackedObjectType(ME->getType()))
-    return 0;
+  if (!isTrackedObjectType(ME->getType())) {
+    if (ScratchArgs.empty())    
+      return 0;
+    
+    return getPersistentSummary(RetEffect::MakeNoRet());
+  }
   
   // EXPERIMENTAL: Assume the Cocoa conventions for all objects returned
   //  by instance methods.





More information about the cfe-commits mailing list