Jordy Rose | 17a38e2 | 2011-09-02 05:55:19 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.cocoa.RetainCount,experimental.core -analyzer-store=region -verify %s |
Ted Kremenek | 3ad2cc8 | 2008-10-22 23:56:21 +0000 | [diff] [blame] | 2 | |
| 3 | typedef const struct __CFString * CFStringRef; |
| 4 | typedef const struct __CFAllocator * CFAllocatorRef; |
| 5 | typedef const struct __CFURL * CFURLRef; |
| 6 | extern CFURLRef CFURLCreateWithString(CFAllocatorRef allocator, CFStringRef URLString, CFURLRef baseURL); |
| 7 | typedef signed char BOOL; |
| 8 | @protocol NSObject - (BOOL)isEqual:(id)object; @end |
| 9 | @interface NSObject <NSObject> {} @end |
| 10 | @class NSArray, NSString, NSURL; |
| 11 | |
Ted Kremenek | b80976c | 2009-02-21 05:13:43 +0000 | [diff] [blame] | 12 | @interface NamingTest : NSObject {} |
Ted Kremenek | af86b0c | 2010-12-17 04:44:43 +0000 | [diff] [blame] | 13 | -(NSObject*)copyPhoto; |
| 14 | -(NSObject*)mutableCopyPhoto; |
Ted Kremenek | 5eef59e | 2010-12-17 07:11:57 +0000 | [diff] [blame] | 15 | -(NSObject*)mutable; |
| 16 | -(NSObject*)mutableCopying; |
Ted Kremenek | b80976c | 2009-02-21 05:13:43 +0000 | [diff] [blame] | 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" |
Ted Kremenek | e973183 | 2009-10-20 00:13:00 +0000 | [diff] [blame] | 21 | -(NSObject*)new_theprefixdoescount; // read as "new theprefixdoescount" |
Ted Kremenek | f0dff4c | 2009-02-23 02:50:20 +0000 | [diff] [blame] | 22 | -(NSObject*)newestAwesomeStuff; // read as "newest awesome stuff" |
| 23 | |
Ted Kremenek | b80976c | 2009-02-21 05:13:43 +0000 | [diff] [blame] | 24 | @end |
| 25 | |
Ted Kremenek | 3ad2cc8 | 2008-10-22 23:56:21 +0000 | [diff] [blame] | 26 | @interface MyClass : NSObject |
| 27 | { |
Ted Kremenek | f4b3548 | 2008-10-24 20:33:56 +0000 | [diff] [blame] | 28 | id myObject; |
Ted Kremenek | 3ad2cc8 | 2008-10-22 23:56:21 +0000 | [diff] [blame] | 29 | } |
| 30 | - (NSURL *)myMethod:(NSString *)inString; |
Ted Kremenek | f4b3548 | 2008-10-24 20:33:56 +0000 | [diff] [blame] | 31 | - (NSURL *)getMethod:(NSString*)inString; |
Ted Kremenek | b7ff4c6 | 2011-02-08 22:54:26 +0000 | [diff] [blame] | 32 | - (NSURL *)getMethod2:(NSString*)inString; |
| 33 | - (void)addObject:(id) __attribute__((ns_consumed)) X; |
| 34 | - (void)addObject2:(id) X; |
Ted Kremenek | 3ad2cc8 | 2008-10-22 23:56:21 +0000 | [diff] [blame] | 35 | @end |
| 36 | |
| 37 | @implementation MyClass |
| 38 | |
| 39 | - (NSURL *)myMethod:(NSString *)inString |
| 40 | { |
Ted Kremenek | cf118d4 | 2009-02-04 23:49:09 +0000 | [diff] [blame] | 41 | NSURL *url = (NSURL *)CFURLCreateWithString(0, (CFStringRef)inString, 0); // expected-warning{{leak}} |
| 42 | return url; |
Ted Kremenek | 3ad2cc8 | 2008-10-22 23:56:21 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Ted Kremenek | f4b3548 | 2008-10-24 20:33:56 +0000 | [diff] [blame] | 45 | - (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 Kremenek | b7ff4c6 | 2011-02-08 22:54:26 +0000 | [diff] [blame] | 52 | - (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 Kremenek | b80976c | 2009-02-21 05:13:43 +0000 | [diff] [blame] | 59 | void testNames(NamingTest* x) { |
Ted Kremenek | af86b0c | 2010-12-17 04:44:43 +0000 | [diff] [blame] | 60 | [x copyPhoto]; // expected-warning{{leak}} |
| 61 | [x mutableCopyPhoto]; // expected-warning{{leak}} |
Ted Kremenek | 5eef59e | 2010-12-17 07:11:57 +0000 | [diff] [blame] | 62 | [x mutable]; // no-warning |
| 63 | [x mutableCopying]; // no-warning |
Ted Kremenek | b80976c | 2009-02-21 05:13:43 +0000 | [diff] [blame] | 64 | [x photocopy]; // no-warning |
Ted Kremenek | af86b0c | 2010-12-17 04:44:43 +0000 | [diff] [blame] | 65 | [x photoCopy]; // no-warning |
| 66 | [x __blebPRCopy]; // no-warning |
Ted Kremenek | b80976c | 2009-02-21 05:13:43 +0000 | [diff] [blame] | 67 | [x __blebPRcopy]; // no-warning |
Ted Kremenek | e973183 | 2009-10-20 00:13:00 +0000 | [diff] [blame] | 68 | [x new_theprefixdoescount]; // expected-warning{{leak}} |
Ted Kremenek | f0dff4c | 2009-02-23 02:50:20 +0000 | [diff] [blame] | 69 | [x newestAwesomeStuff]; // no-warning |
Ted Kremenek | b80976c | 2009-02-21 05:13:43 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Ted Kremenek | f4b3548 | 2008-10-24 20:33:56 +0000 | [diff] [blame] | 72 | |
| 73 | - (void)addObject:(id)X |
| 74 | { |
| 75 | myObject = X; |
| 76 | } |
| 77 | |
Ted Kremenek | b7ff4c6 | 2011-02-08 22:54:26 +0000 | [diff] [blame] | 78 | - (void)addObject2:(id)X |
| 79 | { |
| 80 | myObject = X; |
| 81 | } |
| 82 | |
Ted Kremenek | 3ad2cc8 | 2008-10-22 23:56:21 +0000 | [diff] [blame] | 83 | @end |
Ted Kremenek | b7ff4c6 | 2011-02-08 22:54:26 +0000 | [diff] [blame] | 84 | |