diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
commit | 13cc256e404620c1de0cbcc4e43ce1e2dbbc4898 (patch) | |
tree | 2732d02d7d51218d6eed98ac7fcfc5b8794896b5 /test/Analysis/retain-release-gc-only.m | |
parent | 657bc3d9848e3be92029b2416031340988cd0111 (diff) | |
download | src-13cc256e404620c1de0cbcc4e43ce1e2dbbc4898.tar.gz src-13cc256e404620c1de0cbcc4e43ce1e2dbbc4898.zip |
Vendor import of clang release_32 branch r168974 (effectively, 3.2 RC2):vendor/clang/clang-release_32-r168974
Notes
Notes:
svn path=/vendor/clang/dist/; revision=243791
svn path=/vendor/clang/clang-release_32-r168974/; revision=243792; tag=vendor/clang/clang-release_32-r168974
Diffstat (limited to 'test/Analysis/retain-release-gc-only.m')
-rw-r--r-- | test/Analysis/retain-release-gc-only.m | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/test/Analysis/retain-release-gc-only.m b/test/Analysis/retain-release-gc-only.m index 0340a3c2a140..1a5ed34c9f39 100644 --- a/test/Analysis/retain-release-gc-only.m +++ b/test/Analysis/retain-release-gc-only.m @@ -107,9 +107,14 @@ NSFastEnumerationState; @end @interface NSNumber : NSValue - (char)charValue; - (id)initWithInt:(int)value; @end @class NSString; -@interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration> - (NSUInteger)count; -@end @interface NSArray (NSArrayCreation) + (id)array; -@end @interface NSAutoreleasePool : NSObject { +@interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration> +- (NSUInteger)count; +@end +@interface NSArray (NSArrayCreation) ++ (id)array; ++ (id)arrayWithObjects:(const id [])objects count:(NSUInteger)cnt; +@end + @interface NSAutoreleasePool : NSObject { } - (void)drain; - (id)init; @@ -385,3 +390,45 @@ CFDateRef returnsRetainedCFDate() { return (NSDate*) returnsRetainedCFDate(); // expected-warning{{leak}} } @end + + +#if __has_feature(attribute_ns_consumed) +#define NS_CONSUMED __attribute__((ns_consumed)) +#endif +#if __has_feature(attribute_cf_consumed) +#define CF_CONSUMED __attribute__((cf_consumed)) +#endif + +void consumeAndStopTracking(id NS_CONSUMED obj, void (^callback)(void)); +void CFConsumeAndStopTracking(CFTypeRef CF_CONSUMED obj, void (^callback)(void)); + +void testConsumeAndStopTracking() { + id retained = [@[] retain]; // +0, GC + consumeAndStopTracking(retained, ^{}); // no-warning + + id doubleRetained = [[@[] retain] retain]; // +0, GC + consumeAndStopTracking(doubleRetained, ^{ + [doubleRetained release]; + }); // no-warning + + id unretained = @[]; // +0 + consumeAndStopTracking(unretained, ^{}); // no-warning, GC +} + +void testCFConsumeAndStopTrackingMsg() { + id retained = [@[] retain]; // +0, GC + CFConsumeAndStopTracking((CFTypeRef)retained, ^{}); // expected-warning {{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}} +} + +void testCFConsumeAndStopTracking() { + CFTypeRef retained = returnsRetainedCFDate(); // +1 + CFConsumeAndStopTracking(retained, ^{}); // no-warning + + CFTypeRef doubleRetained = CFRetain(returnsRetainedCFDate()); // +2 + CFConsumeAndStopTracking(doubleRetained, ^{ + CFRelease(doubleRetained); + }); // no-warning + + id unretained = @[]; // +0 + CFConsumeAndStopTracking((CFTypeRef)unretained, ^{}); // expected-warning {{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}} +} |