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

Ted Kremenek kremenek at apple.com
Wed Aug 19 22:13:36 PDT 2009


Author: kremenek
Date: Thu Aug 20 00:13:36 2009
New Revision: 79515

URL: http://llvm.org/viewvc/llvm-project?rev=79515&view=rev
Log:
retain/release checker: Treat NSObject method '-awakeAfterUsingCoder:'
just as if it behaved like an init function.  This fixes <rdar://problem/7129086>.

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=79515&r1=79514&r2=79515&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Thu Aug 20 00:13:36 2009
@@ -635,8 +635,8 @@
   ///  objects.
   RetEffect ObjCAllocRetE;
 
-  /// ObjCInitRetE - Default return effect for init methods returning Objective-C
-  ///  objects.
+  /// ObjCInitRetE - Default return effect for init methods returning 
+  ///   Objective-C objects.
   RetEffect ObjCInitRetE;
   
   RetainSummary DefaultSummary;
@@ -1452,8 +1452,13 @@
   
   // Create the "init" selector.  It just acts as a pass-through for the
   // receiver.
-  addNSObjectMethSummary(GetNullarySelector("init", Ctx),
-                         getPersistentSummary(ObjCInitRetE, DecRefMsg));
+  RetainSummary *InitSumm = getPersistentSummary(ObjCInitRetE, DecRefMsg);  
+  addNSObjectMethSummary(GetNullarySelector("init", Ctx), InitSumm);
+
+  // awakeAfterUsingCoder: behaves basically like an 'init' method.  It
+  // claims the receiver and returns a retained object.
+  addNSObjectMethSummary(GetUnarySelector("awakeAfterUsingCoder", Ctx),
+                         InitSumm);
   
   // The next methods are allocators.
   RetainSummary *AllocSumm = getPersistentSummary(ObjCAllocRetE);  

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

==============================================================================
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Thu Aug 20 00:13:36 2009
@@ -94,19 +94,24 @@
 extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
 typedef struct _NSZone NSZone;
 @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
- at protocol NSObject  - (BOOL)isEqual:(id)object;
+ at protocol NSObject
+- (BOOL)isEqual:(id)object;
 - (id)retain;
 - (oneway void)release;
 - (id)autorelease;
 @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)allocWithZone:(NSZone *)zone;
 + (id)alloc;
 - (void)dealloc;
- at end      extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
+ at end
+ at interface NSObject (NSCoderMethods)
+- (id)awakeAfterUsingCoder:(NSCoder *)aDecoder;
+ at end
+extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
 typedef struct {
 }
 NSFastEnumerationState;
@@ -647,7 +652,8 @@
 @end
 
 //===----------------------------------------------------------------------===//
-//<rdar://problem/6320065> false positive - init method returns an object owned by caller
+//<rdar://problem/6320065> false positive - init method returns an object
+// owned by caller
 //===----------------------------------------------------------------------===//
 
 @interface RDar6320065 : NSObject {
@@ -690,7 +696,21 @@
 }
 
 //===----------------------------------------------------------------------===//
-// <rdar://problem/6859457> [NSData dataWithBytesNoCopy] does not return a retained object
+// <rdar://problem/7129086> -awakeAfterUsingCoder: returns an owned object 
+//  and claims the receiver
+//===----------------------------------------------------------------------===//
+
+ at interface RDar7129086 : NSObject {} @end
+ at implementation RDar7129086
+- (id)awakeAfterUsingCoder:(NSCoder *)aDecoder {
+  [self release]; // no-warning
+  return [NSString alloc];  // no-warning
+}
+ at end
+
+//===----------------------------------------------------------------------===//
+// <rdar://problem/6859457> [NSData dataWithBytesNoCopy] does not return a
+//  retained object
 //===----------------------------------------------------------------------===//
 
 @interface RDar6859457 : NSObject {}





More information about the cfe-commits mailing list