]> granicus.if.org Git - clang/commitdiff
Fix PR 3677 [retain checker]: custom 'allocWithZone' methods should be allowed
authorTed Kremenek <kremenek@apple.com>
Fri, 13 Mar 2009 20:27:06 +0000 (20:27 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 13 Mar 2009 20:27:06 +0000 (20:27 +0000)
to return an owning pointer.

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

lib/Analysis/CFRefCount.cpp
test/Analysis/retain-release.m

index 75a9f3dca108478994c56483ecff43c8ff075cd3..b6c11c9cfc82951b117863a86540d6039f3d4272 100644 (file)
@@ -119,12 +119,15 @@ static NamingConvention deriveNamingConvention(const char* s) {
     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;
     }
     
index c05d73049165373e97dc68d184b0f679310c88aa..c6a05c0031ca9bda5473e95ac78b0c6528a11963 100644 (file)
@@ -60,9 +60,10 @@ typedef struct _NSZone NSZone;
 @end  @protocol NSCopying  - (id)copyWithZone:(NSZone *)zone;
 @end  @protocol NSMutableCopying  - (id)mutableCopyWithZone:(NSZone *)zone;
 @end  @protocol NSCoding  - (void)encodeWithCoder:(NSCoder *)aCoder;
-@end    @interface NSObject <NSObject> {
-}
+@end
+@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 @@ static void rdar_6659160(char *inkind, char *inname)
   [name release];
 }
 
+// PR 3677 - 'allocWithZone' should be treated as following the Cocoa naming
+//  conventions with respect to 'return'ing ownership.
+@interface PR3677: NSObject @end
+@implementation PR3677
++ (id)allocWithZone:(NSZone *)inZone {
+  return [super allocWithZone:inZone];  // no-warning
+}
+@end
+