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