85 lines · plain
1// RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.cocoa.RetainCount,alpha.core -analyzer-config ipa=none -verify %s2 3typedef const struct __CFString * CFStringRef;4typedef const struct __CFAllocator * CFAllocatorRef;5typedef const struct __CFURL * CFURLRef;6extern CFURLRef CFURLCreateWithString(CFAllocatorRef allocator, CFStringRef URLString, CFURLRef baseURL);7typedef signed char BOOL;8@protocol NSObject - (BOOL)isEqual:(id)object; @end9@interface NSObject <NSObject> {} @end10@class NSArray, NSString, NSURL;11 12@interface NamingTest : NSObject {}13-(NSObject*)copyPhoto;14-(NSObject*)mutableCopyPhoto;15-(NSObject*)mutable;16-(NSObject*)mutableCopying;17-(NSObject*)photocopy; // read as "photocopy"18-(NSObject*)photoCopy; // read as "photo Copy"19-(NSObject*)__blebPRCopy; // read as "bleb PRCopy"20-(NSObject*)__blebPRcopy; // read as "bleb P Rcopy"21-(NSObject*)new_theprefixdoescount; // read as "new theprefixdoescount"22-(NSObject*)newestAwesomeStuff; // read as "newest awesome stuff"23 24@end25 26@interface MyClass : NSObject27{28 id myObject;29}30- (NSURL *)myMethod:(NSString *)inString;31- (NSURL *)getMethod:(NSString*)inString;32- (NSURL *)getMethod2:(NSString*)inString;33- (void)addObject:(id) __attribute__((ns_consumed)) X;34- (void)addObject2:(id) X;35@end36 37@implementation MyClass38 39- (NSURL *)myMethod:(NSString *)inString40{41 NSURL *url = (NSURL *)CFURLCreateWithString(0, (CFStringRef)inString, 0); // expected-warning{{leak}}42 return url;43}44 45- (NSURL *)getMethod:(NSString *)inString46{47 NSURL *url = (NSURL *)CFURLCreateWithString(0, (CFStringRef)inString, 0);48 [self addObject:url];49 return url; // no-warning50}51 52- (NSURL *)getMethod2:(NSString *)inString53{54 NSURL *url = (NSURL *)CFURLCreateWithString(0, (CFStringRef)inString, 0); // expected-warning{{leak}}55 [self addObject2:url];56 return url;57}58 59void testNames(NamingTest* x) {60 [x copyPhoto]; // expected-warning{{leak}}61 [x mutableCopyPhoto]; // expected-warning{{leak}}62 [x mutable]; // no-warning63 [x mutableCopying]; // no-warning64 [x photocopy]; // no-warning65 [x photoCopy]; // no-warning66 [x __blebPRCopy]; // no-warning67 [x __blebPRcopy]; // no-warning68 [x new_theprefixdoescount]; // expected-warning{{leak}}69 [x newestAwesomeStuff]; // no-warning70}71 72 73- (void)addObject:(id)X74{75 myObject = X;76}77 78- (void)addObject2:(id)X79{80 myObject = X;81}82 83@end84 85