diff options
author | Ted Kremenek <kremenek@apple.com> | 2012-09-07 07:40:40 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2012-09-07 07:40:40 +0000 |
commit | 971073b8e4eb82fa1bae9d2b0d354f35a54099ee (patch) | |
tree | b7be3ba7add9d8f38cddff61583515e8b90ac249 | |
parent | 2ab012a6de2b2769ec7ad99c4b61788cc5175d17 (diff) |
Revert "Rework the retain-release.m test to use FileCheck and the "text" output"
Apparently the output of this test is not deterministic. Needs investigation.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163377 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | test/Analysis/retain-release.m | 1528 |
1 files changed, 180 insertions, 1348 deletions
diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m index 10753b46c6..3a9649c741 100644 --- a/test/Analysis/retain-release.m +++ b/test/Analysis/retain-release.m @@ -1,7 +1,5 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.cocoa.RetainCount -analyzer-store=region -analyzer-output=text -fblocks -Wno-objc-root-class %s > %t.objc 2>&1 -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.cocoa.RetainCount -analyzer-store=region -analyzer-output=text -fblocks -Wno-objc-root-class -x objective-c++ %s > %t.objcpp 2>&1 -// RUN: FileCheck -exact-match -input-file=%t.objc %s -// RUN: FileCheck -exact-match -input-file=%t.objcpp %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.cocoa.RetainCount -analyzer-store=region -fblocks -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.cocoa.RetainCount -analyzer-store=region -fblocks -verify -x objective-c++ -Wno-objc-root-class %s #if __has_feature(attribute_ns_returns_retained) #define NS_RETURNS_RETAINED __attribute__((ns_returns_retained)) @@ -319,9 +317,9 @@ CFAbsoluteTime f1() { CFDateRef date = CFDateCreate(0, t); CFRetain(date); CFRelease(date); - CFDateGetAbsoluteTime(date); + CFDateGetAbsoluteTime(date); // no-warning CFRelease(date); - t = CFDateGetAbsoluteTime(date); + t = CFDateGetAbsoluteTime(date); // expected-warning{{Reference-counted object is used after it is released}} return t; } @@ -330,9 +328,9 @@ CFAbsoluteTime f2() { CFDateRef date = CFDateCreate(0, t); [((NSDate*) date) retain]; CFRelease(date); - CFDateGetAbsoluteTime(date); + CFDateGetAbsoluteTime(date); // no-warning [((NSDate*) date) release]; - t = CFDateGetAbsoluteTime(date); + t = CFDateGetAbsoluteTime(date); // expected-warning{{Reference-counted object is used after it is released}} return t; } @@ -347,10 +345,10 @@ CFAbsoluteTime f3() { CFDateRef date = CFDateCreate(0, t); [((NSDate*) date) retain]; CFRelease(date); - CFDateGetAbsoluteTime(date); + CFDateGetAbsoluteTime(date); // no-warning global_x = (NSDate*) date; [((NSDate*) date) release]; - t = CFDateGetAbsoluteTime(date); + t = CFDateGetAbsoluteTime(date); // no-warning return t; } @@ -363,7 +361,7 @@ CFAbsoluteTime f3() { CFAbsoluteTime f5(int x) { CFAbsoluteTime t = CFAbsoluteTimeGetCurrent(); - CFDateRef date = CFDateCreate(0, t); + CFDateRef date = CFDateCreate(0, t); // expected-warning{{leak}} if (x) CFRelease(date); @@ -374,7 +372,7 @@ CFAbsoluteTime f5(int x) { // Test a leak involving the return. CFDateRef f6(int x) { - CFDateRef date = CFDateCreate(0, CFAbsoluteTimeGetCurrent()); + CFDateRef date = CFDateCreate(0, CFAbsoluteTimeGetCurrent()); // expected-warning{{leak}} CFRetain(date); return date; } @@ -384,7 +382,7 @@ CFDateRef f6(int x) { CFDateRef f7() { CFDateRef date = CFDateCreate(0, CFAbsoluteTimeGetCurrent()); //expected-warning{{leak}} CFRetain(date); - date = CFDateCreate(0, CFAbsoluteTimeGetCurrent()); + date = CFDateCreate(0, CFAbsoluteTimeGetCurrent()); // expected-warning {{leak}} return date; } @@ -393,16 +391,16 @@ CFDateRef f7() { CFDateRef MyDateCreate(); CFDateRef f8() { - CFDateRef date = MyDateCreate(); + CFDateRef date = MyDateCreate(); // expected-warning{{leak}} CFRetain(date); return date; } __attribute__((cf_returns_retained)) CFDateRef f9() { - CFDateRef date = CFDateCreate(0, CFAbsoluteTimeGetCurrent()); + CFDateRef date = CFDateCreate(0, CFAbsoluteTimeGetCurrent()); // no-warning int *p = 0; // When allocations fail, CFDateCreate can return null. - if (!date) *p = 1; + if (!date) *p = 1; // expected-warning{{null}} return date; } @@ -411,23 +409,23 @@ __attribute__((cf_returns_retained)) CFDateRef f9() { // http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/DiscArbitrationFramework/ // void f10(io_service_t media, DADiskRef d, CFStringRef s) { - DADiskRef disk = DADiskCreateFromBSDName(kCFAllocatorDefault, 0, "hello"); + DADiskRef disk = DADiskCreateFromBSDName(kCFAllocatorDefault, 0, "hello"); // expected-warning{{leak}} if (disk) NSLog(@"ok"); - disk = DADiskCreateFromIOMedia(kCFAllocatorDefault, 0, media); + disk = DADiskCreateFromIOMedia(kCFAllocatorDefault, 0, media); // expected-warning{{leak}} if (disk) NSLog(@"ok"); - CFDictionaryRef dict = DADiskCopyDescription(d); + CFDictionaryRef dict = DADiskCopyDescription(d); // expected-warning{{leak}} if (dict) NSLog(@"ok"); - disk = DADiskCopyWholeDisk(d); + disk = DADiskCopyWholeDisk(d); // expected-warning{{leak}} if (disk) NSLog(@"ok"); - DADissenterRef dissenter = DADissenterCreate(kCFAllocatorDefault, + DADissenterRef dissenter = DADissenterCreate(kCFAllocatorDefault, // expected-warning{{leak}} kDAReturnSuccess, s); if (dissenter) NSLog(@"ok"); - DASessionRef session = DASessionCreate(kCFAllocatorDefault); + DASessionRef session = DASessionCreate(kCFAllocatorDefault); // expected-warning{{leak}} if (session) NSLog(@"ok"); } @@ -444,16 +442,16 @@ void f11() { CFArrayAppendValue(A, s1); // Decrement the reference count. - CFRelease(s1); + CFRelease(s1); // no-warning // Get the string. We don't own it. s1 = (CFStringRef) CFArrayGetValueAtIndex(A, 0); // Release the array. - CFRelease(A); + CFRelease(A); // no-warning // Release the string. This is a bug. - CFRelease(s1); + CFRelease(s1); // expected-warning{{Incorrect decrement of the reference count}} } // PR 3337: Handle functions declared using typedefs. @@ -461,40 +459,40 @@ typedef CFTypeRef CREATEFUN(); CREATEFUN MyCreateFun; void f12() { - CFTypeRef o = MyCreateFun(); + CFTypeRef o = MyCreateFun(); // expected-warning {{leak}} } void f13_autorelease() { - CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); - [(id) A autorelease]; + CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning + [(id) A autorelease]; // no-warning } void f13_autorelease_b() { CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); [(id) A autorelease]; - [(id) A autorelease]; + [(id) A autorelease]; // expected-warning{{Object sent -autorelease too many times}} } CFMutableArrayRef f13_autorelease_c() { CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); [(id) A autorelease]; [(id) A autorelease]; - return A; + return A; // expected-warning{{Object sent -autorelease too many times}} } CFMutableArrayRef f13_autorelease_d() { CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); [(id) A autorelease]; [(id) A autorelease]; - CFMutableArrayRef B = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); - CFRelease(B); + CFMutableArrayRef B = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning{{Object sent -autorelease too many times}} + CFRelease(B); // no-warning while (1) {} } // This case exercises the logic where the leak site is the same as the allocation site. void f14_leakimmediately() { - CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); + CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning{{leak}} } // Test that we track an allocated object beyond the point where the *name* @@ -504,7 +502,7 @@ void f15() { CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); CFMutableArrayRef *B = &A; // At this point, the name 'A' is no longer live. - CFRelease(*B); + CFRelease(*B); // no-warning } // Test when we pass NULL to CFRetain/CFRelease. @@ -513,10 +511,10 @@ void f16(int x, CFTypeRef p) { return; if (x) { - CFRelease(p); + CFRelease(p); // expected-warning{{Null pointer argument in call to CFRelease}} } else { - CFRetain(p); + CFRetain(p); // expected-warning{{Null pointer argument in call to CFRetain}} } } @@ -525,12 +523,12 @@ void f17(int x, CFTypeRef p) { if (x) { CFRelease(p); if (!p) - CFRelease(0); + CFRelease(0); // no-warning } else { CFRetain(p); if (!p) - CFRetain(0); + CFRetain(0); // no-warning } } @@ -545,7 +543,7 @@ void f17(int x, CFTypeRef p) { @implementation SelfIvarTest - (void)test_self_tracking { - myObj = (id) CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); + myObj = (id) CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning } @end @@ -558,7 +556,7 @@ void f17(int x, CFTypeRef p) { @implementation TestReturnNotOwnedWhenExpectedOwned - (NSString*)newString { NSString *s = [NSString stringWithUTF8String:"hello"]; - return s; + return s; // expected-warning{{Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected}} } @end @@ -571,7 +569,7 @@ static void rdar_6659160(char *inkind, char *inname) // will be a toggled flag in the future. It can indeed return null, but // Cocoa programmers generally aren't expected to reason about out-of-memory // conditions. - NSString *kind = [[NSString alloc] initWithUTF8String:inkind]; + NSString *kind = [[NSString alloc] initWithUTF8String:inkind]; // expected-warning{{leak}} // We do allow stringWithUTF8String to fail. This isn't really correct, as // far as returning 0. In most error conditions it will throw an exception. @@ -593,13 +591,13 @@ static void rdar_6659160(char *inkind, char *inname) kindC = [kind UTF8String]; if(name) nameC = [name UTF8String]; - if(!isFoo(kindC[0])) + if(!isFoo(kindC[0])) // expected-warning{{null}} return; - if(!isFoo(nameC[0])) + if(!isFoo(nameC[0])) // no-warning return; [kind release]; - [name release]; + [name release]; // expected-warning{{Incorrect decrement of the reference count}} } // PR 3677 - 'allocWithZone' should be treated as following the Cocoa naming @@ -607,14 +605,14 @@ static void rdar_6659160(char *inkind, char *inname) @interface PR3677: NSObject @end @implementation PR3677 + (id)allocWithZone:(NSZone *)inZone { - return [super allocWithZone:inZone]; + return [super allocWithZone:inZone]; // no-warning } @end // PR 3820 - Reason about calls to -dealloc void pr3820_DeallocInsteadOfRelease(void) { - id foo = [[NSString alloc] init]; + id foo = [[NSString alloc] init]; // no-warning [foo dealloc]; // foo is not leaked, since it has been deallocated. } @@ -623,7 +621,7 @@ void pr3820_ReleaseAfterDealloc(void) { id foo = [[NSString alloc] init]; [foo dealloc]; - [foo release]; + [foo release]; // expected-warning{{used after it is release}} // NSInternalInconsistencyException: message sent to deallocated object } @@ -632,7 +630,7 @@ void pr3820_DeallocAfterRelease(void) NSLog(@"\n\n[%s]", __FUNCTION__); id foo = [[NSString alloc] init]; [foo release]; - [foo dealloc]; + [foo dealloc]; // expected-warning{{used after it is released}} // message sent to released object } @@ -648,7 +646,7 @@ void rdar6704930(unsigned char *s, unsigned int length) { if (*s == ':') { ++s; --length; - name = [[NSString alloc] init]; + name = [[NSString alloc] init]; // no-warning break; } ++s; @@ -659,7 +657,7 @@ void rdar6704930(unsigned char *s, unsigned int length) { name = 0; } if (length == 0) { // no ':' found -> use it all as name - name = [[NSString alloc] init]; + name = [[NSString alloc] init]; // no-warning } } } @@ -684,7 +682,7 @@ void rdar6704930(unsigned char *s, unsigned int length) { @implementation rdar_6833332 @synthesize window; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - NSMutableDictionary *dict = [[NSMutableDictionary dictionaryWithCapacity:4] retain]; + NSMutableDictionary *dict = [[NSMutableDictionary dictionaryWithCapacity:4] retain]; // expected-warning{{leak}} [dict setObject:@"foo" forKey:@"bar"]; @@ -696,7 +694,7 @@ void rdar6704930(unsigned char *s, unsigned int length) { } - (void)radar10102244 { - NSMutableDictionary *dict = [[NSMutableDictionary dictionaryWithCapacity:4] retain]; + NSMutableDictionary *dict = [[NSMutableDictionary dictionaryWithCapacity:4] retain]; // expected-warning{{leak}} if (window) NSLog(@"%@", window); } @@ -709,7 +707,7 @@ void rdar6704930(unsigned char *s, unsigned int length) { int rdar_6257780_Case1() { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSArray *array = [NSArray array]; - [array release]; + [array release]; // expected-warning{{Incorrect decrement of the reference count of an object that is not owned at this point by the caller}} [pool drain]; return 0; } @@ -734,7 +732,7 @@ void rdar_6866843() { [dictionary setObject:array forKey:@"key"]; [array release]; // Using 'array' here should be fine - NSLog(@"array = %@\n", array); + NSLog(@"array = %@\n", array); // no-warning // Now the array is released [dictionary release]; [pool drain]; @@ -754,10 +752,10 @@ typedef CFTypeRef OtherRef; @implementation RDar6877235 - (CFTypeRef)_copyCFTypeRef { - return [[NSString alloc] init]; + return [[NSString alloc] init]; // no-warning } - (OtherRef)_copyOtherRef { - return [[NSString alloc] init]; + return [[NSString alloc] init]; // no-warning } @end @@ -780,18 +778,18 @@ typedef CFTypeRef OtherRef; @implementation RDar6320065 - (id)initReturningNewClass { [self release]; - self = [[RDar6320065Subclass alloc] init]; + self = [[RDar6320065Subclass alloc] init]; // no-warning return self; } - (id)_initReturningNewClassBad { [self release]; - [[RDar6320065Subclass alloc] init]; + [[RDar6320065Subclass alloc] init]; // expected-warning {{leak}} return self; } - (id)initReturningNewClassBad2 { [self release]; self = [[RDar6320065Subclass alloc] init]; - return [self autorelease]; + return [self autorelease]; // expected-warning{{Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected}} } @end @@ -800,7 +798,7 @@ typedef CFTypeRef OtherRef; @end int RDar6320065_test() { - RDar6320065 *test = [[RDar6320065 alloc] init]; + RDar6320065 *test = [[RDar6320065 alloc] init]; // no-warning [test release]; return 0; } @@ -813,8 +811,8 @@ int RDar6320065_test() { @interface RDar7129086 : NSObject {} @end @implementation RDar7129086 - (id)awakeAfterUsingCoder:(NSCoder *)aDecoder { - [self release]; - return [NSString alloc]; + [self release]; // no-warning + return [NSString alloc]; // no-warning } @end @@ -829,15 +827,15 @@ int RDar6320065_test() { @end @implementation RDar6859457 -- (NSString*) NoCopyString { return [[NSString alloc] init]; } -- (NSString*) noCopyString { return [[NSString alloc] init]; } +- (NSString*) NoCopyString { return [[NSString alloc] init]; } // expected-warning{{leak}} +- (NSString*) noCopyString { return [[NSString alloc] init]; } // expected-warning{{leak}} @end void test_RDar6859457(RDar6859457 *x, void *bytes, NSUInteger dataLength) { - [x NoCopyString]; - [x noCopyString]; - [NSData dataWithBytesNoCopy:bytes length:dataLength]; - [NSData dataWithBytesNoCopy:bytes length:dataLength freeWhenDone:1]; + [x NoCopyString]; // expected-warning{{leak}} + [x noCopyString]; // expected-warning{{leak}} + [NSData dataWithBytesNoCopy:bytes length:dataLength]; // no-warning + [NSData dataWithBytesNoCopy:bytes length:dataLength freeWhenDone:1]; // no-warning } //===----------------------------------------------------------------------===// @@ -847,8 +845,8 @@ void test_RDar6859457(RDar6859457 *x, void *bytes, NSUInteger dataLength) { static void PR4230(void) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSString *object = [[[NSString alloc] init] autorelease]; + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // no-warning + NSString *object = [[[NSString alloc] init] autorelease]; // no-warning return; } @@ -862,7 +860,7 @@ static void PR4230(void) @implementation TestNullIdentifier + (id):(int)x, ... { - return [[NSString alloc] init]; + return [[NSString alloc] init]; // expected-warning{{leak}} } @end @@ -881,7 +879,7 @@ typedef struct s6893565* TD6893565; @implementation RDar6893565 -(TD6893565)newThing { - return (TD6893565) [[NSString alloc] init]; + return (TD6893565) [[NSString alloc] init]; // no-warning } @end @@ -892,10 +890,10 @@ typedef struct s6893565* TD6893565; void rdar6902710(QCView *view, QCRenderer *renderer, CIContext *context, NSString *str, CIImage *img, CGRect rect, CIFormat form, CGColorSpaceRef cs) { - [view createSnapshotImageOfType:str]; - [renderer createSnapshotImageOfType:str]; - [context createCGImage:img fromRect:rect]; - [context createCGImage:img fromRect:rect format:form colorSpace:cs]; + [view createSnapshotImageOfType:str]; // expected-warning{{leak}} + [renderer createSnapshotImageOfType:str]; // expected-warning{{leak}} + [context createCGImage:img fromRect:rect]; // expected-warning{{leak}} + [context createCGImage:img fromRect:rect format:form colorSpace:cs]; // expected-warning{{leak}} } //===----------------------------------------------------------------------===// @@ -904,7 +902,7 @@ void rdar6902710(QCView *view, QCRenderer *renderer, CIContext *context, //===----------------------------------------------------------------------===// void rdar6945561(CIContext *context, CGSize size, CFDictionaryRef d) { - [context createCGLayerWithSize:size info:d]; + [context createCGLayerWithSize:size info:d]; // expected-warning{{leak}} } //===----------------------------------------------------------------------===// @@ -913,15 +911,15 @@ void rdar6945561(CIContext *context, CGSize size, CFDictionaryRef d) { //===----------------------------------------------------------------------===// void IOBSDNameMatching_wrapper(mach_port_t masterPort, uint32_t options, const char * bsdName) { - IOBSDNameMatching(masterPort, options, bsdName); + IOBSDNameMatching(masterPort, options, bsdName); // expected-warning{{leak}} } void IOServiceMatching_wrapper(const char * name) { - IOServiceMatching(name); + IOServiceMatching(name); // expected-warning{{leak}} } void IOServiceNameMatching_wrapper(const char * name) { - IOServiceNameMatching(name); + IOServiceNameMatching(name); // expected-warning{{leak}} } CF_RETURNS_RETAINED CFDictionaryRef CreateDict(); @@ -931,29 +929,29 @@ void IOServiceAddNotification_wrapper(mach_port_t masterPort, const io_name_t no CFDictionaryRef matching = CreateDict(); CFRelease(matching); - IOServiceAddNotification(masterPort, notificationType, matching, + IOServiceAddNotification(masterPort, notificationType, matching, // expected-warning{{used after it is released}} expected-warning{{deprecated}} wakePort, reference, notification); } void IORegistryEntryIDMatching_wrapper(uint64_t entryID ) { - IORegistryEntryIDMatching(entryID); + IORegistryEntryIDMatching(entryID); // expected-warning{{leak}} } void IOOpenFirmwarePathMatching_wrapper(mach_port_t masterPort, uint32_t options, const char * path) { - IOOpenFirmwarePathMatching(masterPort, options, path); + IOOpenFirmwarePathMatching(masterPort, options, path); // expected-warning{{leak}} } void IOServiceGetMatchingService_wrapper(mach_port_t masterPort) { CFDictionaryRef matching = CreateDict(); IOServiceGetMatchingService(masterPort, matching); - CFRelease(matching); + CFRelease(matching); // expected-warning{{used after it is released}} } void IOServiceGetMatchingServices_wrapper(mach_port_t masterPort, io_iterator_t *existing) { CFDictionaryRef matching = CreateDict(); IOServiceGetMatchingServices(masterPort, matching, existing); - CFRelease(matching); + CFRelease(matching); // expected-warning{{used after it is released}} } void IOServiceAddMatchingNotification_wrapper(IONotificationPortRef notifyPort, const io_name_t notificationType, @@ -961,7 +959,7 @@ void IOServiceAddMatchingNotification_wrapper(IONotificationPortRef notifyPort, CFDictionaryRef matching = CreateDict(); IOServiceAddMatchingNotification(notifyPort, notificationType, matching, callback, refCon, notification); - CFRelease(matching); + CFRelease(matching); // expected-warning{{used after it is released}} } //===----------------------------------------------------------------------===// @@ -978,9 +976,9 @@ void rdar_6539791(CFMutableDictionaryRef y, void* key, void* val_key) { signed z = 1; CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z); if (value) { - CFDictionaryAddValue(x, val_key, (void*)value); + CFDictionaryAddValue(x, val_key, (void*)value); // no-warning CFRelease(value); - CFDictionaryAddValue(y, val_key, (void*)value); + CFDictionaryAddValue(y, val_key, (void*)value); // no-warning } } @@ -993,7 +991,7 @@ void rdar_6560661(CFMutableArrayRef x) { CFArrayAppendValue(x, value); CFRelease(value); CFRetain(value); - CFRelease(value); + CFRelease(value); // no-warning } // <rdar://problem/7152619> @@ -1002,7 +1000,7 @@ void rdar_7152619(CFStringRef str) { CFAttributedStringRef string = CFAttributedStringCreate(kCFAllocatorDefault, str, 0); CFMutableAttributedStringRef attrString = CFAttributedStringCreateMutableCopy(kCFAllocatorDefault, 100, string); CFRelease(string); - NSNumber *number = [[NSNumber alloc] initWithInt:5]; + NSNumber *number = [[NSNumber alloc] initWithInt:5]; // expected-warning{{leak}} CFAttributedStringSetAttribute(attrString, CFRangeMake(0, 1), str, number); [number release]; [number retain]; @@ -1027,7 +1025,7 @@ void rdar_7184450(CGContextRef myContext, CGFloat x, CGPoint myStartPoint, }; // End color CGGradientRef myGradient = - CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), + CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), // expected-warning{{leak}} components, locations, num_locations); CGContextDrawLinearGradient(myContext, myGradient, myStartPoint, myEndPoint, @@ -1049,7 +1047,7 @@ void rdar_7184450_pos(CGContextRef myContext, CGFloat x, CGPoint myStartPoint, }; // End color CGGradientRef myGradient = - CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), components, locations, num_locations); + CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), components, locations, num_locations); // expected-warning 2 {{leak}} CGContextDrawLinearGradient(myContext, myGradient, myStartPoint, myEndPoint, 0); @@ -1083,11 +1081,11 @@ void *rdar_7299394_start_routine(void *p) { return 0; } void rdar_7299394(pthread_attr_t *attr, pthread_t *thread, void *args) { - NSNumber *number = [[NSNumber alloc] initWithInt:5]; + NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning pthread_create(thread, attr, rdar_7299394_start_routine, number); } void rdar_7299394_positive(pthread_attr_t *attr, pthread_t *thread) { - NSNumber *number = [[NSNumber alloc] initWithInt:5]; + NSNumber *number = [[NSNumber alloc] initWithInt:5]; // expected-warning{{leak}} } //===----------------------------------------------------------------------===// @@ -1096,7 +1094,7 @@ void rdar_7299394_positive(pthread_attr_t *attr, pthread_t *thread) { //===----------------------------------------------------------------------===// void rdar11282706(pthread_key_t key) { - NSNumber *number = [[NSNumber alloc] initWithInt:5]; + NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning pthread_setspecific(key, (void*) number); } @@ -1171,7 +1169,7 @@ CVReturn rdar_7283567(CFAllocatorRef allocator, size_t width, size_t height, // For the allocated object, it doesn't really matter what type it is // for the purpose of this test. All we want to show is that // this is freed later by the callback. - NSNumber *number = [[NSNumber alloc] initWithInt:5]; + NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning return CVPixelBufferCreateWithBytes(allocator, width, height, pixelFormatType, baseAddress, bytesPerRow, releaseCallback, @@ -1190,7 +1188,7 @@ CVReturn rdar_7283567_2(CFAllocatorRef allocator, size_t width, size_t height, // For the allocated object, it doesn't really matter what type it is // for the purpose of this test. All we want to show is that // this is freed later by the callback. - NSNumber *number = [[NSNumber alloc] initWithInt:5]; + NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning return CVPixelBufferCreateWithPlanarBytes(allocator, width, height, pixelFormatType, dataPtr, dataSize, @@ -1220,9 +1218,9 @@ void rdar_7358899(void *data, // For the allocated object, it doesn't really matter what type it is // for the purpose of this test. All we want to show is that // this is freed later by the callback. - NSNumber *number = [[NSNumber alloc] initWithInt:5]; + NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning - CGBitmapContextCreateWithData(data, width, height, bitsPerComponent, + CGBitmapContextCreateWithData(data, width, height, bitsPerComponent, // expected-warning{{leak}} bytesPerRow, space, bitmapInfo, releaseCallback, number); } @@ -1240,11 +1238,11 @@ void rdar_7358899(void *data, @end void rdar7265711_a(RDar7265711 *x) { - id y = [x new_stuff]; + id y = [x new_stuff]; // expected-warning{{leak}} } void rdar7265711_b(RDar7265711 *x) { - id y = [x new_stuff]; + id y = [x new_stuff]; // no-warning [y release]; } @@ -1260,8 +1258,8 @@ void rdar7265711_b(RDar7265711 *x) { void rdar7306898(void) { // 'dragCopyCursor' does not follow Cocoa's fundamental rule. It is a noun, not an sentence // implying a 'copy' of something. - NSCursor *c = [NSCursor dragCopyCursor]; - NSNumber *number = [[NSNumber alloc] initWithInt:5]; + NSCursor *c = [NSCursor dragCopyCursor]; // no-warning + NSNumber *number = [[NSNumber alloc] initWithInt:5]; // expected-warning{{leak}} } //===----------------------------------------------------------------------===// @@ -1271,10 +1269,10 @@ void rdar7306898(void) { @interface RDar7252064 : NSObject @end void rdar7252064(void) { - [RDar7252064 release]; - [RDar7252064 retain]; - [RDar7252064 autorelease]; - [NSAutoreleasePool drain]; + [RDar7252064 release]; // expected-warning{{The 'release' message should be sent to instances of class 'RDar7252064' and not the class directly}} + [RDar7252064 retain]; // expected-warning{{The 'retain' message should be sent to instances of class 'RDar7252064' and not the class directly}} + [RDar7252064 autorelease]; // expected-warning{{The 'autorelease' message should be sent to instances of class 'RDar7252064' and not the class directly}} + [NSAutoreleasePool drain]; // expected-warning{{method '+drain' not found}} expected-warning{{The 'drain' message should be sent to instances of class 'NSAutoreleasePool' and not the class directly}} } //===----------------------------------------------------------------------===// @@ -1286,38 +1284,38 @@ typedef NSString* MyStringTy; @protocol FooP; @interface TestOwnershipAttr : NSObject -- (NSString*) returnsAnOwnedString NS_RETURNS_RETAINED; -- (NSString*) returnsAnOwnedCFString CF_RETURNS_RETAINED; -- (MyStringTy) returnsAnOwnedTypedString NS_RETURNS_RETAINED; -- (NSString*) newString NS_RETURNS_NOT_RETAINED; +- (NSString*) returnsAnOwnedString NS_RETURNS_RETAINED; // no-warning +- (NSString*) returnsAnOwnedCFString CF_RETURNS_RETAINED; // no-warning +- (MyStringTy) returnsAnOwnedTypedString NS_RETURNS_RETAINED; // no-warning +- (NSString*) newString NS_RETURNS_NOT_RETAINED; // no-warning - (NSString*) newStringNoAttr; -- (int) returnsAnOwnedInt NS_RETURNS_RETAINED; +- (int) returnsAnOwnedInt NS_RETURNS_RETAINED; // expected-warning{{'ns_returns_retained' attribute only applies to methods that return an Objective-C object}} - (id) pseudoInit NS_CONSUMES_SELF NS_RETURNS_RETAINED; + (void) consume:(id) NS_CONSUMED x; + (void) consume2:(id) CF_CONSUMED x; @end -static int ownership_attribute_doesnt_go_here NS_RETURNS_RETAINED; +static int ownership_attribute_doesnt_go_here NS_RETURNS_RETAINED; // expected-warning{{'ns_returns_retained' attribute only applies to functions and methods}} void test_attr_1(TestOwnershipAttr *X) { - NSString *str = [X returnsAnOwnedString]; + NSString *str = [X returnsAnOwnedString]; // expected-warning{{leak}} } void test_attr_1b(TestOwnershipAttr *X) { - NSString *str = [X returnsAnOwnedCFString]; + NSString *str = [X returnsAnOwnedCFString]; // expected-warning{{leak}} } void test_attr1c(TestOwnershipAttr *X) { - NSString *str = [X newString]; - NSString *str2 = [X newStringNoAttr]; + NSString *str = [X newString]; // no-warning + NSString *str2 = [X newStringNoAttr]; // expected-warning{{leak}} } void testattr2_a() { - TestOwnershipAttr *x = [TestOwnershipAttr alloc]; + TestOwnershipAttr *x = [TestOwnershipAttr alloc]; // expected-warning{{leak}} } void testattr2_b() { - TestOwnershipAttr *x = [[TestOwnershipAttr alloc] pseudoInit]; + TestOwnershipAttr *x = [[TestOwnershipAttr alloc] pseudoInit]; // expected-warning{{leak}} } void testattr2_b_11358224_self_assign_looses_the_leak() { @@ -1326,14 +1324,14 @@ void testattr2_b_11358224_self_assign_looses_the_leak() { } void testattr2_c() { - TestOwnershipAttr *x = [[TestOwnershipAttr alloc] pseudoInit]; + TestOwnershipAttr *x = [[TestOwnershipAttr alloc] pseudoInit]; // no-warning [x release]; } void testattr3() { - TestOwnershipAttr *x = [TestOwnershipAttr alloc]; + TestOwnershipAttr *x = [TestOwnershipAttr alloc]; // no-warning [TestOwnershipAttr consume:x]; - TestOwnershipAttr *y = [TestOwnershipAttr alloc]; + TestOwnershipAttr *y = [TestOwnershipAttr alloc]; // no-warning [TestOwnershipAttr consume2:y]; } @@ -1341,19 +1339,19 @@ void consume_ns(id NS_CONSUMED x); void consume_cf(id CF_CONSUMED x); void testattr4() { - TestOwnershipAttr *x = [TestOwnershipAttr alloc]; + TestOwnershipAttr *x = [TestOwnershipAttr alloc]; // no-warning consume_ns(x); - TestOwnershipAttr *y = [TestOwnershipAttr alloc]; + TestOwnershipAttr *y = [TestOwnershipAttr alloc]; // no-warning consume_cf(y); } @interface TestOwnershipAttr2 : NSObject -- (NSString*) newString NS_RETURNS_NOT_RETAINED; +- (NSString*) newString NS_RETURNS_NOT_RETAINED; // no-warning @end @implementation TestOwnershipAttr2 - (NSString*) newString { - return [NSString alloc]; + return [NSString alloc]; // expected-warning {{Potential leak of an object}} } @end @@ -1386,20 +1384,20 @@ CFDateRef returnsRetainedCFDate() { } - (CFDateRef) newCFRetainedAsCFNoAttr { - return (CFDateRef)[(id)[self returnsCFRetainedAsCF] autorelease]; + return (CFDateRef)[(id)[self returnsCFRetainedAsCF] autorelease]; // expected-warning{{Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected}} } - (NSDate*) alsoReturnsRetained { - return (NSDate*) returnsRetainedCFDate(); + return (NSDate*) returnsRetainedCFDate(); // expected-warning{{leak}} } - (CFDateRef) alsoReturnsRetainedAsCF { - return returnsRetainedCFDate(); + return returnsRetainedCFDate(); // expected-warning{{leak}} } - (NSDate*) returnsNSRetained { - return (NSDate*) returnsRetainedCFDate(); + return (NSDate*) returnsRetainedCFDate(); // no-warning } @end @@ -1415,25 +1413,25 @@ void panic_not_in_hardcoded_list() __attribute__((noreturn)); void test_panic_negative() { signed z = 1; - CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z); + CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z); // expected-warning{{leak}} } void test_panic_positive() { signed z = 1; - CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z); + CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z); // no-warning panic(); } void test_panic_neg_2(int x) { signed z = 1; - CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z); + CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z); // expected-warning{{leak}} if (x) panic(); } void test_panic_pos_2(int x) { signed z = 1; - CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z); + CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z); // no-warning if (x) panic(); if (!x) { @@ -1449,28 +1447,28 @@ void test_panic_pos_2(int x) { //===----------------------------------------------------------------------===// void test_blocks_1_pos(void) { - NSNumber *number = [[NSNumber alloc] initWithInt:5]; + NSNumber *number = [[NSNumber alloc] initWithInt:5]; // expected-warning{{leak}} ^{}(); } void test_blocks_1_indirect_release(void) { - NSNumber *number = [[NSNumber alloc] initWithInt:5]; + NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning ^{ [number release]; }(); } void test_blocks_1_indirect_retain(void) { // Eventually this should be reported as a leak. - NSNumber *number = [[NSNumber alloc] initWithInt:5]; + NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning ^{ [number retain]; }(); } void test_blocks_1_indirect_release_via_call(void) { - NSNumber *number = [[NSNumber alloc] initWithInt:5]; + NSNumber *number = [[NSNumber alloc] initWithInt:5]; // no-warning ^(NSObject *o){ [o release]; }(number); } void test_blocks_1_indirect_retain_via_call(void) { - NSNumber *number = [[NSNumber alloc] initWithInt:5]; + NSNumber *number = [[NSNumber alloc] initWithInt:5]; // expected-warning {{leak}} ^(NSObject *o){ [o retain]; }(number); } @@ -1505,7 +1503,7 @@ void r8272168() { - (NSDate*) rdar8356342:(NSDate*)inValue { NSDate *outValue = inValue; if (outValue == 0) - outValue = [[NSDate alloc] init]; + outValue = [[NSDate alloc] init]; // no-warning if (outValue != inValue) [outValue autorelease]; @@ -1528,7 +1526,7 @@ static void rdar_8724287(CFErrorRef error) while (error_to_dump != ((void*)0)) { CFDictionaryRef info; - info = CFErrorCopyUserInfo(error_to_dump); + info = CFErrorCopyUserInfo(error_to_dump); // expected-warning{{Potential leak of an object}} if (info != ((void*)0)) { } @@ -1574,52 +1572,52 @@ void rdar9726279() { // Test camelcase support for CF conventions. While Core Foundation APIs // don't use camel casing, other code is allowed to use it. CFArrayRef camelcase_create_1() { - return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning } CFArrayRef camelcase_createno() { - return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning {{leak}} } CFArrayRef camelcase_copy() { - return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning } CFArrayRef camelcase_copying() { - return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning {{leak}} } CFArrayRef copyCamelCase() { - return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning } CFArrayRef __copyCamelCase() { - return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning } CFArrayRef __createCamelCase() { - return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning } CFArrayRef camel_create() { - return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning } CFArrayRef camel_creat() { - return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning {{leak}} } CFArrayRef camel_copy() { - return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning } CFArrayRef camel_copyMachine() { - return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); + return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning } CFArrayRef camel_copymachine() { - return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); |