blob: aff713be49f258acf160a38320dddf876754a90f [file] [log] [blame]
Jordy Rose17a38e22011-09-02 05:55:19 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.cocoa.RetainCount,experimental.core -analyzer-store=region -verify %s
Ted Kremenek3ad2cc82008-10-22 23:56:21 +00002
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; @end
9@interface NSObject <NSObject> {} @end
10@class NSArray, NSString, NSURL;
11
Ted Kremenekb80976c2009-02-21 05:13:43 +000012@interface NamingTest : NSObject {}
Ted Kremenekaf86b0c2010-12-17 04:44:43 +000013-(NSObject*)copyPhoto;
14-(NSObject*)mutableCopyPhoto;
Ted Kremenek5eef59e2010-12-17 07:11:57 +000015-(NSObject*)mutable;
16-(NSObject*)mutableCopying;
Ted Kremenekb80976c2009-02-21 05:13:43 +000017-(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"
Ted Kremeneke9731832009-10-20 00:13:00 +000021-(NSObject*)new_theprefixdoescount; // read as "new theprefixdoescount"
Ted Kremenekf0dff4c2009-02-23 02:50:20 +000022-(NSObject*)newestAwesomeStuff; // read as "newest awesome stuff"
23
Ted Kremenekb80976c2009-02-21 05:13:43 +000024@end
25
Ted Kremenek3ad2cc82008-10-22 23:56:21 +000026@interface MyClass : NSObject
27{
Ted Kremenekf4b35482008-10-24 20:33:56 +000028 id myObject;
Ted Kremenek3ad2cc82008-10-22 23:56:21 +000029}
30- (NSURL *)myMethod:(NSString *)inString;
Ted Kremenekf4b35482008-10-24 20:33:56 +000031- (NSURL *)getMethod:(NSString*)inString;
Ted Kremenekb7ff4c62011-02-08 22:54:26 +000032- (NSURL *)getMethod2:(NSString*)inString;
33- (void)addObject:(id) __attribute__((ns_consumed)) X;
34- (void)addObject2:(id) X;
Ted Kremenek3ad2cc82008-10-22 23:56:21 +000035@end
36
37@implementation MyClass
38
39- (NSURL *)myMethod:(NSString *)inString
40{
Ted Kremenekcf118d42009-02-04 23:49:09 +000041 NSURL *url = (NSURL *)CFURLCreateWithString(0, (CFStringRef)inString, 0); // expected-warning{{leak}}
42 return url;
Ted Kremenek3ad2cc82008-10-22 23:56:21 +000043}
44
Ted Kremenekf4b35482008-10-24 20:33:56 +000045- (NSURL *)getMethod:(NSString *)inString
46{
47 NSURL *url = (NSURL *)CFURLCreateWithString(0, (CFStringRef)inString, 0);
48 [self addObject:url];
49 return url; // no-warning
50}
51
Ted Kremenekb7ff4c62011-02-08 22:54:26 +000052- (NSURL *)getMethod2:(NSString *)inString
53{
54 NSURL *url = (NSURL *)CFURLCreateWithString(0, (CFStringRef)inString, 0); // expected-warning{{leak}}
55 [self addObject2:url];
56 return url;
57}
58
Ted Kremenekb80976c2009-02-21 05:13:43 +000059void testNames(NamingTest* x) {
Ted Kremenekaf86b0c2010-12-17 04:44:43 +000060 [x copyPhoto]; // expected-warning{{leak}}
61 [x mutableCopyPhoto]; // expected-warning{{leak}}
Ted Kremenek5eef59e2010-12-17 07:11:57 +000062 [x mutable]; // no-warning
63 [x mutableCopying]; // no-warning
Ted Kremenekb80976c2009-02-21 05:13:43 +000064 [x photocopy]; // no-warning
Ted Kremenekaf86b0c2010-12-17 04:44:43 +000065 [x photoCopy]; // no-warning
66 [x __blebPRCopy]; // no-warning
Ted Kremenekb80976c2009-02-21 05:13:43 +000067 [x __blebPRcopy]; // no-warning
Ted Kremeneke9731832009-10-20 00:13:00 +000068 [x new_theprefixdoescount]; // expected-warning{{leak}}
Ted Kremenekf0dff4c2009-02-23 02:50:20 +000069 [x newestAwesomeStuff]; // no-warning
Ted Kremenekb80976c2009-02-21 05:13:43 +000070}
71
Ted Kremenekf4b35482008-10-24 20:33:56 +000072
73- (void)addObject:(id)X
74{
75 myObject = X;
76}
77
Ted Kremenekb7ff4c62011-02-08 22:54:26 +000078- (void)addObject2:(id)X
79{
80 myObject = X;
81}
82
Ted Kremenek3ad2cc82008-10-22 23:56:21 +000083@end
Ted Kremenekb7ff4c62011-02-08 22:54:26 +000084