]> granicus.if.org Git - clang/commitdiff
Add a few passing test cases for finding leaks of retained objects stored to arrays...
authorTed Kremenek <kremenek@apple.com>
Thu, 15 Oct 2009 23:44:02 +0000 (23:44 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 15 Oct 2009 23:44:02 +0000 (23:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84221 91177308-0d34-0410-b5e6-96231b3b80d8

test/Analysis/retain-release-region-store.m

index 7a696833f92dfd6a0bc14ae3c284be9a0f2de727..c6f9cffc5f7201d2149985e5dc58a9a9a42c8832 100644 (file)
@@ -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 <NSObject> {
-}
-@end  typedef float CGFloat;
+@end
+@interface NSObject <NSObject> {}
++ (id)allocWithZone:(NSZone *)zone;
++ (id)alloc;
+- (void)dealloc;
+@end
+typedef float CGFloat;
 typedef double NSTimeInterval;
 @interface NSDate : NSObject <NSCopying, NSCoding>  - (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;
 }
 
+//===----------------------------------------------------------------------===//
+// <rdar://problem/7283470>
+//===----------------------------------------------------------------------===//
+
+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}} 
+  };
+}
+