diff options
Diffstat (limited to 'test/Analysis/retain-release-gc-only.m')
-rw-r--r-- | test/Analysis/retain-release-gc-only.m | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/Analysis/retain-release-gc-only.m b/test/Analysis/retain-release-gc-only.m index cc4a40d..ec33a57 100644 --- a/test/Analysis/retain-release-gc-only.m +++ b/test/Analysis/retain-release-gc-only.m @@ -5,6 +5,8 @@ // Header stuff. //===----------------------------------------------------------------------===// +typedef struct objc_class *Class; + typedef unsigned int __darwin_natural_t; typedef struct {} div_t; typedef unsigned long UInt32; @@ -56,6 +58,7 @@ typedef struct _NSZone NSZone; @end @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end @interface NSObject <NSObject> {} +- (Class)class; + (id)alloc; + (id)allocWithZone:(NSZone *)zone; @end typedef float CGFloat; @@ -173,6 +176,28 @@ void f5b() { @end //===----------------------------------------------------------------------===// +// <rdar://problem/6948053> False positive: object substitution during -init* +// methods warns about returning +0 when using -fobjc-gc-only +//===----------------------------------------------------------------------===// + +@interface MyClassRdar6948053 : NSObject +- (id) init; ++ (id) shared; +@end + +@implementation MyClassRdar6948053 ++(id) shared { + return (id) 0; +} +- (id) init +{ + Class myClass = [self class]; + [self release]; + return [[myClass shared] retain]; // no-warning +} +@end + +//===----------------------------------------------------------------------===// // Tests of ownership attributes. //===----------------------------------------------------------------------===// @@ -189,3 +214,27 @@ void test_attr_1b(TestOwnershipAttr *X) { NSString *str = [X returnsAnOwnedCFString]; // expected-warning{{leak}} } +@interface MyClassTestCFAttr : NSObject {} +- (NSDate*) returnsCFRetained __attribute__((cf_returns_retained)); +- (NSDate*) alsoReturnsRetained; +- (NSDate*) returnsNSRetained __attribute__((ns_returns_retained)); +@end + +__attribute__((cf_returns_retained)) +CFDateRef returnsRetainedCFDate() { + return CFDateCreate(0, CFAbsoluteTimeGetCurrent()); +} + +@implementation MyClassTestCFAttr +- (NSDate*) returnsCFRetained { + return (NSDate*) returnsRetainedCFDate(); // No leak. +} + +- (NSDate*) alsoReturnsRetained { + return (NSDate*) returnsRetainedCFDate(); // expected-warning{{leak}} +} + +- (NSDate*) returnsNSRetained { + return (NSDate*) returnsRetainedCFDate(); // expected-warning{{leak}} +} +@end
\ No newline at end of file |