[cfe-commits] r71921 - in /cfe/trunk: lib/Analysis/CFRefCount.cpp test/Analysis/retain-release.m

Ted Kremenek kremenek at apple.com
Fri May 15 18:38:02 PDT 2009


Author: kremenek
Date: Fri May 15 20:38:01 2009
New Revision: 71921

URL: http://llvm.org/viewvc/llvm-project?rev=71921&view=rev
Log:
Fix: <rdar://problem/6893565> False positive: don't flag leaks for return types that cannot be determined to be CF types

Modified:
    cfe/trunk/lib/Analysis/CFRefCount.cpp
    cfe/trunk/test/Analysis/retain-release.m

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

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Fri May 15 20:38:01 2009
@@ -894,11 +894,18 @@
   if (!OT)
     return true;
     
-  // Does the interface subclass NSObject?
-  // FIXME: We can memoize here if this gets too expensive.  
-  IdentifierInfo* NSObjectII = &Ctx.Idents.get("NSObject");
+  // Does the interface subclass NSObject?    
+  // FIXME: We can memoize here if this gets too expensive.    
   ObjCInterfaceDecl* ID = OT->getDecl();  
 
+  // Assume that anything declared with a forward declaration and no
+  // @interface subclasses NSObject.
+  if (ID->isForwardDecl())
+    return true;
+  
+  IdentifierInfo* NSObjectII = &Ctx.Idents.get("NSObject");
+
+
   for ( ; ID ; ID = ID->getSuperClass())
     if (ID->getIdentifier() == NSObjectII)
       return true;
@@ -3142,22 +3149,24 @@
       RetEffect RE = Summ.getRetEffect();
       bool hasError = false;
 
-      if (isGCEnabled() && RE.getObjKind() == RetEffect::ObjC) {
-        // Things are more complicated with garbage collection.  If the
-        // returned object is suppose to be an Objective-C object, we have
-        // a leak (as the caller expects a GC'ed object) because no
-        // method should return ownership unless it returns a CF object.
-        X = X ^ RefVal::ErrorGCLeakReturned;
-        
-        // Keep this false until this is properly tested.
-        hasError = true;
-      }
-      else if (!RE.isOwned()) {
-        // Either we are using GC and the returned object is a CF type
-        // or we aren't using GC.  In either case, we expect that the
-        // enclosing method is expected to return ownership.        
-        hasError = true;
-        X = X ^ RefVal::ErrorLeakReturned;
+      if (RE.getKind() != RetEffect::NoRet) {
+        if (isGCEnabled() && RE.getObjKind() == RetEffect::ObjC) {
+          // Things are more complicated with garbage collection.  If the
+          // returned object is suppose to be an Objective-C object, we have
+          // a leak (as the caller expects a GC'ed object) because no
+          // method should return ownership unless it returns a CF object.
+          X = X ^ RefVal::ErrorGCLeakReturned;
+          
+          // Keep this false until this is properly tested.
+          hasError = true;
+        }
+        else if (!RE.isOwned()) {
+          // Either we are using GC and the returned object is a CF type
+          // or we aren't using GC.  In either case, we expect that the
+          // enclosing method is expected to return ownership.        
+          hasError = true;
+          X = X ^ RefVal::ErrorLeakReturned;
+        }
       }
       
       if (hasError) {        

Modified: cfe/trunk/test/Analysis/retain-release.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.m?rev=71921&r1=71920&r2=71921&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Fri May 15 20:38:01 2009
@@ -632,6 +632,25 @@
 }
 
 //===----------------------------------------------------------------------===//
+// <rdar://problem/6893565> don't flag leaks for return types that cannot be 
+//                          determined to be CF types
+//===----------------------------------------------------------------------===//
+
+// We don't know if 'struct s6893565' represents a Core Foundation type, so
+// we shouldn't emit an error here.
+typedef struct s6893565* TD6893565;
+
+ at interface RDar6893565 {}
+-(TD6893565)newThing;
+ at end
+
+ at implementation RDar6893565
+-(TD6893565)newThing {  
+  return (TD6893565) [[NSString alloc] init]; // no-warning
+}
+ at end
+
+//===----------------------------------------------------------------------===//
 // Tests of ownership attributes.
 //===----------------------------------------------------------------------===//
 





More information about the cfe-commits mailing list