diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Analysis/retain-release-path-notes.m | 48 | ||||
-rw-r--r-- | clang/test/Analysis/retain-release.m | 21 |
2 files changed, 67 insertions, 2 deletions
diff --git a/clang/test/Analysis/retain-release-path-notes.m b/clang/test/Analysis/retain-release-path-notes.m index c3f5fcda444..be6336b59f7 100644 --- a/clang/test/Analysis/retain-release-path-notes.m +++ b/clang/test/Analysis/retain-release-path-notes.m @@ -130,3 +130,51 @@ CFTypeRef CFGetRuleViolation () { return result; // expected-warning{{Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected}} expected-note{{Object returned to caller with a +0 retain count}} expected-note{{Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected}} } @end + + +typedef unsigned long NSUInteger; + +@interface NSValue : NSObject +@end + +@interface NSNumber : NSValue ++ (NSNumber *)numberWithInt:(int)i; +@end + +@interface NSString : NSObject ++ (NSString *)stringWithUTF8String:(const char *)str; +@end + +@interface NSArray : NSObject ++ (NSArray *)arrayWithObjects:(const id [])objects count:(NSUInteger)count; +@end + +@interface NSDictionary : NSObject ++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id /* <NSCopying> */ [])keys count:(NSUInteger)count; +@end + + +void testNumericLiteral() { + id result = @1; // expected-note{{NSNumber literal is an object with a +0 retain count}} + [result release]; // expected-warning{{decrement}} expected-note{{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}} +} + +void testBoxedInt(int x) { + id result = @(x); // expected-note{{NSNumber boxed expression produces an object with a +0 retain count}} + [result release]; // expected-warning{{decrement}} expected-note{{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}} +} + +void testBoxedString(const char *str) { + id result = @(str); // expected-note{{NSString boxed expression produces an object with a +0 retain count}} + [result release]; // expected-warning{{decrement}} expected-note{{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}} +} + +void testArray(id obj) { + id result = @[obj]; // expected-note{{NSArray literal is an object with a +0 retain count}} + [result release]; // expected-warning{{decrement}} expected-note{{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}} +} + +void testDictionary(id key, id value) { + id result = @{key: value}; // expected-note{{NSDictionary literal is an object with a +0 retain count}} + [result release]; // expected-warning{{decrement}} expected-note{{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}} +} diff --git a/clang/test/Analysis/retain-release.m b/clang/test/Analysis/retain-release.m index a27fdac27fb..1274b197bf3 100644 --- a/clang/test/Analysis/retain-release.m +++ b/clang/test/Analysis/retain-release.m @@ -142,9 +142,13 @@ NSFastEnumerationState; @end @class NSString, NSDictionary; @interface NSValue : NSObject <NSCopying, NSCoding> - (void)getValue:(void *)value; -@end @interface NSNumber : NSValue - (char)charValue; +@end +@interface NSNumber : NSValue +- (char)charValue; - (id)initWithInt:(int)value; -@end @class NSString; ++ (NSNumber *)numberWithInt:(int)value; +@end +@class NSString; @interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration> - (NSUInteger)count; - (id)initWithObjects:(const id [])objects count:(NSUInteger)cnt; @@ -1812,6 +1816,19 @@ void test_objc_arrays() { } } +void test_objc_integer_literals() { + id value = [@1 retain]; // expected-warning {{leak}} + [value description]; +} + +void test_objc_boxed_expressions(int x, const char *y) { + id value = [@(x) retain]; // expected-warning {{leak}} + [value description]; + + value = [@(y) retain]; // expected-warning {{leak}} + [value description]; +} + // Test NSLog doesn't escape tracked objects. void rdar11400885(int y) { |