blob: 9ffbf6c341d8ed4f73d115bf26e0cfe54dd72dfa [file] [log] [blame]
Ted Kremenekbe1fe1e2009-02-17 04:27:41 +00001// RUN: clang -analyze -checker-cfref -analyzer-store=basic -verify %s &&
2// RUN: clang -analyze -checker-cfref -analyzer-store=region -verify %s
Ted Kremenek3ad2cc82008-10-22 23:56:21 +00003
4typedef const struct __CFString * CFStringRef;
5typedef const struct __CFAllocator * CFAllocatorRef;
6typedef const struct __CFURL * CFURLRef;
7extern CFURLRef CFURLCreateWithString(CFAllocatorRef allocator, CFStringRef URLString, CFURLRef baseURL);
8typedef signed char BOOL;
9@protocol NSObject - (BOOL)isEqual:(id)object; @end
10@interface NSObject <NSObject> {} @end
11@class NSArray, NSString, NSURL;
12
Ted Kremenekb80976c2009-02-21 05:13:43 +000013@interface NamingTest : NSObject {}
14-(NSObject*)photocopy; // read as "photocopy"
15-(NSObject*)photoCopy; // read as "photo Copy"
16-(NSObject*)__blebPRCopy; // read as "bleb PRCopy"
17-(NSObject*)__blebPRcopy; // read as "bleb P Rcopy"
18-(NSObject*)new_theprefixdoesnotcount; // read as "theprefixdoesnotcount"
19@end
20
Ted Kremenek3ad2cc82008-10-22 23:56:21 +000021@interface MyClass : NSObject
22{
Ted Kremenekf4b35482008-10-24 20:33:56 +000023 id myObject;
Ted Kremenek3ad2cc82008-10-22 23:56:21 +000024}
25- (NSURL *)myMethod:(NSString *)inString;
Ted Kremenekf4b35482008-10-24 20:33:56 +000026- (NSURL *)getMethod:(NSString*)inString;
27- (void)addObject:(id)X;
Ted Kremenek3ad2cc82008-10-22 23:56:21 +000028@end
29
30@implementation MyClass
31
32- (NSURL *)myMethod:(NSString *)inString
33{
Ted Kremenekcf118d42009-02-04 23:49:09 +000034 NSURL *url = (NSURL *)CFURLCreateWithString(0, (CFStringRef)inString, 0); // expected-warning{{leak}}
35 return url;
Ted Kremenek3ad2cc82008-10-22 23:56:21 +000036}
37
Ted Kremenekf4b35482008-10-24 20:33:56 +000038- (NSURL *)getMethod:(NSString *)inString
39{
40 NSURL *url = (NSURL *)CFURLCreateWithString(0, (CFStringRef)inString, 0);
41 [self addObject:url];
42 return url; // no-warning
43}
44
Ted Kremenekb80976c2009-02-21 05:13:43 +000045void testNames(NamingTest* x) {
46 [x photocopy]; // no-warning
47 [x photoCopy]; // expected-warning{{leak}}
48 [x __blebPRCopy]; // expected-warning{{leak}}
49 [x __blebPRcopy]; // no-warning
50 [x new_theprefixdoesnotcount]; // no-warning
51}
52
Ted Kremenekf4b35482008-10-24 20:33:56 +000053
54- (void)addObject:(id)X
55{
56 myObject = X;
57}
58
Ted Kremenek3ad2cc82008-10-22 23:56:21 +000059@end