• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.cocoa.RetainCount,alpha.core -analyzer-config ipa=none -analyzer-store=region -verify %s
2
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
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@end
25
26@interface MyClass : NSObject
27{
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@end
36
37@implementation MyClass
38
39- (NSURL *)myMethod:(NSString *)inString
40{
41  NSURL *url = (NSURL *)CFURLCreateWithString(0, (CFStringRef)inString, 0); // expected-warning{{leak}}
42  return url;
43}
44
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
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
59void testNames(NamingTest* x) {
60  [x copyPhoto]; // expected-warning{{leak}}
61  [x mutableCopyPhoto]; // expected-warning{{leak}}
62  [x mutable]; // no-warning
63  [x mutableCopying]; // no-warning
64  [x photocopy]; // no-warning
65  [x photoCopy]; // no-warning
66  [x __blebPRCopy]; // no-warning
67  [x __blebPRcopy]; // no-warning
68  [x new_theprefixdoescount]; // expected-warning{{leak}}
69  [x newestAwesomeStuff]; // no-warning
70}
71
72
73- (void)addObject:(id)X
74{
75  myObject = X;
76}
77
78- (void)addObject2:(id)X
79{
80  myObject = X;
81}
82
83@end
84
85