summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-08-20 05:13:36 +0000
committerTed Kremenek <kremenek@apple.com>2009-08-20 05:13:36 +0000
commit815fbb60269499aa7a6a1b4ce5fc364c223ec5cf (patch)
tree1701a50b4e1b5d7ecfa76daae014ff0cbb2b223a
parent4d2836634234c41ed2357e01df729d64813eb094 (diff)
downloadbcm5719-llvm-815fbb60269499aa7a6a1b4ce5fc364c223ec5cf.tar.gz
bcm5719-llvm-815fbb60269499aa7a6a1b4ce5fc364c223ec5cf.zip
retain/release checker: Treat NSObject method '-awakeAfterUsingCoder:'
just as if it behaved like an init function. This fixes <rdar://problem/7129086>. llvm-svn: 79515
-rw-r--r--clang/lib/Analysis/CFRefCount.cpp13
-rw-r--r--clang/test/Analysis/retain-release.m32
2 files changed, 35 insertions, 10 deletions
diff --git a/clang/lib/Analysis/CFRefCount.cpp b/clang/lib/Analysis/CFRefCount.cpp
index b965393601c..1b7a746f263 100644
--- a/clang/lib/Analysis/CFRefCount.cpp
+++ b/clang/lib/Analysis/CFRefCount.cpp
@@ -635,8 +635,8 @@ class VISIBILITY_HIDDEN RetainSummaryManager {
/// 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 @@ void RetainSummaryManager::InitializeMethodSummaries() {
// 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);
diff --git a/clang/test/Analysis/retain-release.m b/clang/test/Analysis/retain-release.m
index e39bae9126d..a510f441174 100644
--- a/clang/test/Analysis/retain-release.m
+++ b/clang/test/Analysis/retain-release.m
@@ -94,19 +94,24 @@ typedef unsigned long NSUInteger;
extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
typedef struct _NSZone NSZone;
@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
-@protocol NSObject - (BOOL)isEqual:(id)object;
+@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;
-@end @interface NSObject <NSObject> {
-}
+@end
+@interface NSObject <NSObject> {}
+ (id)allocWithZone:(NSZone *)zone;
+ (id)alloc;
- (void)dealloc;
-@end extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
+@end
+@interface NSObject (NSCoderMethods)
+- (id)awakeAfterUsingCoder:(NSCoder *)aDecoder;
+@end
+extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
typedef struct {
}
NSFastEnumerationState;
@@ -647,7 +652,8 @@ typedef CFTypeRef OtherRef;
@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 @@ int RDar6320065_test() {
}
//===----------------------------------------------------------------------===//
-// <rdar://problem/6859457> [NSData dataWithBytesNoCopy] does not return a retained object
+// <rdar://problem/7129086> -awakeAfterUsingCoder: returns an owned object
+// and claims the receiver
+//===----------------------------------------------------------------------===//
+
+@interface RDar7129086 : NSObject {} @end
+@implementation RDar7129086
+- (id)awakeAfterUsingCoder:(NSCoder *)aDecoder {
+ [self release]; // no-warning
+ return [NSString alloc]; // no-warning
+}
+@end
+
+//===----------------------------------------------------------------------===//
+// <rdar://problem/6859457> [NSData dataWithBytesNoCopy] does not return a
+// retained object
//===----------------------------------------------------------------------===//
@interface RDar6859457 : NSObject {}
OpenPOWER on IntegriCloud