]> granicus.if.org Git - clang/commitdiff
retain/release checker: more hacks to workaround false positives cause by
authorTed Kremenek <kremenek@apple.com>
Fri, 24 Apr 2009 18:00:17 +0000 (18:00 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 24 Apr 2009 18:00:17 +0000 (18:00 +0000)
delegates. When a reference counted object is passed as to a 'void*' argument to
a method stop tracking the reference count.

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

lib/Analysis/CFRefCount.cpp

index 8be76d82897518c4f502482e939c739bcb235301..1021574de608d7b4de42733ab534ad5c710be9e3 100644 (file)
@@ -1076,9 +1076,28 @@ RetainSummaryManager::getInitMethodSummary(ObjCMessageExpr* ME) {
 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.