refcnt_naming.m revision af86b0c160bc998bdde2f35d526ca819d7b3a1f2
1// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -verify %s
2// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s
3
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
13@interface NamingTest : NSObject {}
14-(NSObject*)copyPhoto;
15-(NSObject*)mutableCopyPhoto;
16-(NSObject*)photocopy;    // read as "photocopy"
17-(NSObject*)photoCopy;    // read as "photo Copy"
18-(NSObject*)__blebPRCopy; // read as "bleb PRCopy"
19-(NSObject*)__blebPRcopy; // read as "bleb P Rcopy"
20-(NSObject*)new_theprefixdoescount; // read as "new theprefixdoescount"
21-(NSObject*)newestAwesomeStuff; // read as "newest awesome stuff"
22
23@end
24
25@interface MyClass : NSObject
26{
27  id myObject;
28}
29- (NSURL *)myMethod:(NSString *)inString;
30- (NSURL *)getMethod:(NSString*)inString;
31- (void)addObject:(id)X;
32@end
33
34@implementation MyClass
35
36- (NSURL *)myMethod:(NSString *)inString
37{
38  NSURL *url = (NSURL *)CFURLCreateWithString(0, (CFStringRef)inString, 0); // expected-warning{{leak}}
39  return url;
40}
41
42- (NSURL *)getMethod:(NSString *)inString
43{
44  NSURL *url = (NSURL *)CFURLCreateWithString(0, (CFStringRef)inString, 0);
45  [self addObject:url];
46  return url; // no-warning
47}
48
49void testNames(NamingTest* x) {
50  [x copyPhoto]; // expected-warning{{leak}}
51  [x mutableCopyPhoto]; // expected-warning{{leak}}
52  [x photocopy]; // no-warning
53  [x photoCopy]; // no-warning
54  [x __blebPRCopy]; // no-warning
55  [x __blebPRcopy]; // no-warning
56  [x new_theprefixdoescount]; // expected-warning{{leak}}
57  [x newestAwesomeStuff]; // no-warning
58}
59
60
61- (void)addObject:(id)X
62{
63  myObject = X;
64}
65
66@end
67