From 47dcd06e113c5a3b6621166acdb163734a1cfa33 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 15 Oct 2009 23:44:02 +0000 Subject: [PATCH] Add a few passing test cases for finding leaks of retained objects stored to arrays (). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84221 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Analysis/retain-release-region-store.m | 43 +++++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/test/Analysis/retain-release-region-store.m b/test/Analysis/retain-release-region-store.m index 7a696833f9..c6f9cffc5f 100644 --- a/test/Analysis/retain-release-region-store.m +++ b/test/Analysis/retain-release-region-store.m @@ -43,14 +43,19 @@ typedef mach_port_name_t mach_port_t; typedef signed char BOOL; 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; @end @protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; -@end @interface NSObject { -} -@end typedef float CGFloat; +@end +@interface NSObject {} ++ (id)allocWithZone:(NSZone *)zone; ++ (id)alloc; +- (void)dealloc; +@end +typedef float CGFloat; typedef double NSTimeInterval; @interface NSDate : NSObject - (NSTimeInterval)timeIntervalSinceReferenceDate; @end enum { @@ -74,6 +79,9 @@ kDAReturnSuccess = 0, kDAReturnError = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff typedef mach_error_t DAReturn; typedef const struct __DADissenter * DADissenterRef; extern DADissenterRef DADissenterCreate( CFAllocatorRef allocator, DAReturn status, CFStringRef string ); +@interface NSNumber : NSObject + - (id)initWithInt:(int)value; + @end //===----------------------------------------------------------------------===// // Test cases. @@ -140,3 +148,30 @@ CFDateRef rdar7257223_Create_2(void) { return s.x; } +//===----------------------------------------------------------------------===// +// +//===----------------------------------------------------------------------===// + +void rdar7283470(void) { + NSNumber *numbers[] = { + [[NSNumber alloc] initWithInt:1], // no-warning + [[NSNumber alloc] initWithInt:2], // no-warning + [[NSNumber alloc] initWithInt:3], // no-warning + [[NSNumber alloc] initWithInt:4], // no-warning + [[NSNumber alloc] initWithInt:5] // no-warning + }; + + for (unsigned i = 0 ; i < sizeof(numbers) / sizeof(numbers[0]) ; ++i) + [numbers[i] release]; +} + +void rdar7283470_positive(void) { + NSNumber *numbers[] = { + [[NSNumber alloc] initWithInt:1], // expected-warning{{leak}} + [[NSNumber alloc] initWithInt:2], // expected-warning{{leak}} + [[NSNumber alloc] initWithInt:3], // expected-warning{{leak}} + [[NSNumber alloc] initWithInt:4], // expected-warning{{leak}} + [[NSNumber alloc] initWithInt:5] // expected-warning{{leak}} + }; +} + -- 2.40.0