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

Ted Kremenek kremenek at apple.com
Fri Mar 13 13:27:07 PDT 2009


Author: kremenek
Date: Fri Mar 13 15:27:06 2009
New Revision: 66934

URL: http://llvm.org/viewvc/llvm-project?rev=66934&view=rev
Log:
Fix PR 3677 [retain checker]: custom 'allocWithZone' methods should be allowed
to return an owning pointer.

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=66934&r1=66933&r2=66934&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Fri Mar 13 15:27:06 2009
@@ -119,12 +119,15 @@
     case 4:
       // Methods starting with 'alloc' or contain 'copy' follow the
       // create rule
-      if ((AtBeginning && StringsEqualNoCase("alloc", s, len)) ||
-          (C == NoConvention && StringsEqualNoCase("copy", s, len)))
+      if (C == NoConvention && StringsEqualNoCase("copy", s, len))
         C = CreateRule;
       else // Methods starting with 'init' follow the init rule.
         if (AtBeginning && StringsEqualNoCase("init", s, len))
-        C = InitRule;      
+          C = InitRule;
+      break;
+    case 5:
+      if (AtBeginning && StringsEqualNoCase("alloc", s, len))
+        C = CreateRule;
       break;
     }
     

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

==============================================================================
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Fri Mar 13 15:27:06 2009
@@ -60,9 +60,10 @@
 @end  @protocol NSCopying  - (id)copyWithZone:(NSZone *)zone;
 @end  @protocol NSMutableCopying  - (id)mutableCopyWithZone:(NSZone *)zone;
 @end  @protocol NSCoding  - (void)encodeWithCoder:(NSCoder *)aCoder;
- at end    @interface NSObject <NSObject> {
-}
+ at end
+ at interface NSObject <NSObject> {}
 + (id)alloc;
++ (id)allocWithZone:(NSZone *)zone;
 @end   typedef float CGFloat;
 @interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>    - (NSUInteger)length;
 - (const char *)UTF8String;
@@ -324,3 +325,12 @@
   [name release];
 }
 
+// PR 3677 - 'allocWithZone' should be treated as following the Cocoa naming
+//  conventions with respect to 'return'ing ownership.
+ at interface PR3677: NSObject @end
+ at implementation PR3677
++ (id)allocWithZone:(NSZone *)inZone {
+  return [super allocWithZone:inZone];  // no-warning
+}
+ at end
+





More information about the cfe-commits mailing list