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

Ted Kremenek kremenek at apple.com
Thu Apr 23 12:11:35 PDT 2009


Author: kremenek
Date: Thu Apr 23 14:11:35 2009
New Revision: 69908

URL: http://llvm.org/viewvc/llvm-project?rev=69908&view=rev
Log:
Per discussions with Ken Ferry and Paul Marks (<rdar://problem/6815234>) greatly
extend the number of objects tracked by the retain/release checker by assuming
that all class and instance methods should follow Cocoa object "getter" and
"alloc/new" conventions.

Modified:
    cfe/trunk/lib/Analysis/CFRefCount.cpp
    cfe/trunk/test/Analysis/NSString.m
    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=69908&r1=69907&r2=69908&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Thu Apr 23 14:11:35 2009
@@ -1074,15 +1074,18 @@
   if (!isTrackedObjectType(Ctx.getCanonicalType(ME->getType())))
     return 0;
 
-  if (followsFundamentalRule(s)) {    
-    RetEffect E = isGCEnabled() ? RetEffect::MakeNoRet()
-                                : RetEffect::MakeOwned(RetEffect::ObjC, true);
-    RetainSummary* Summ = getPersistentSummary(E);
-    ObjCMethodSummaries[ME] = Summ;
-    return Summ;
-  }
+  // EXPERIMENTAL: Assume the Cocoa conventions for all objects returned
+  //  by instance methods.
+
+  RetEffect E =
+    followsFundamentalRule(s)
+    ? (isGCEnabled() ? RetEffect::MakeNotOwned(RetEffect::ObjC)
+                     : RetEffect::MakeOwned(RetEffect::ObjC, true))
+    : RetEffect::MakeNotOwned(RetEffect::ObjC);
   
-  return 0;
+  RetainSummary* Summ = getPersistentSummary(E);
+  ObjCMethodSummaries[ME] = Summ;
+  return Summ;
 }
 
 RetainSummary*
@@ -1099,7 +1102,17 @@
   if (I != ObjCClassMethodSummaries.end())
     return I->second;
   
-  return 0;
+  // EXPERIMENTAL: Assume the Cocoa conventions for all objects returned
+  //  by class methods.
+  const char* s = S.getIdentifierInfoForSlot(0)->getName();
+  RetEffect E = followsFundamentalRule(s)
+    ? (isGCEnabled() ? RetEffect::MakeNotOwned(RetEffect::ObjC)
+       : RetEffect::MakeOwned(RetEffect::ObjC, true))
+    : RetEffect::MakeNotOwned(RetEffect::ObjC);
+  
+  RetainSummary* Summ = getPersistentSummary(E);
+  ObjCClassMethodSummaries[ObjCSummaryKey(ClsName, S)] = Summ;
+  return Summ;
 }
 
 void RetainSummaryManager::InitializeClassMethodSummaries() {
@@ -2351,9 +2364,8 @@
     BadRelease(CFRefCount* tf) : CFRefBug(tf, "bad release") {}
 
     const char* getDescription() const {
-      return "Incorrect decrement of the reference count of a "
-      "Core Foundation object ("
-      "the object is not owned at this point by the caller)";
+      return "Incorrect decrement of the reference count of an "
+             "object is not owned at this point by the caller";
     }
   };
   

Modified: cfe/trunk/test/Analysis/NSString.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/NSString.m?rev=69908&r1=69907&r2=69908&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/NSString.m (original)
+++ cfe/trunk/test/Analysis/NSString.m Thu Apr 23 14:11:35 2009
@@ -73,6 +73,7 @@
 - (NSComparisonResult)compare:(NSString *)string options:(NSStringCompareOptions)mask range:(NSRange)compareRange locale:(id)locale;
 - (NSComparisonResult)caseInsensitiveCompare:(NSString *)string;
 - (NSArray *)componentsSeparatedByCharactersInSet:(NSCharacterSet *)separator;
++ (id)stringWithFormat:(NSString *)format, ... __attribute__((format(__NSString__, 1, 2)));
 @end
 @interface NSSimpleCString : NSString {} @end
 @interface NSConstantString : NSSimpleCString @end
@@ -243,3 +244,10 @@
     [old release];
 }
 
+// Test stringWithFormat (<rdar://problem/6815234>)
+void test_stringWithFormat() {  
+  NSString *string = [[NSString stringWithFormat:@"%ld", (long) 100] retain];
+  [string release];
+  [string release]; // expected-warning{{Incorrect decrement of the reference count}}
+}
+

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

==============================================================================
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Thu Apr 23 14:11:35 2009
@@ -335,7 +335,7 @@
     return;
 
   [kind release];
-  [name release];
+  [name release]; // expected-warning{{Incorrect decrement of the reference count}}
 }
 
 // PR 3677 - 'allocWithZone' should be treated as following the Cocoa naming





More information about the cfe-commits mailing list