• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clang_cc1 -analyze -analyze-function="myMethodWithY:withX:" -analyzer-checker=core,osx.cocoa.RetainCount -analyzer-store=region -verify %s
2
3typedef signed char BOOL;
4typedef unsigned int NSUInteger;
5typedef struct _NSZone NSZone;
6@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
7@protocol NSObject  - (BOOL)isEqual:(id)object; @end
8@protocol NSCopying  - (id)copyWithZone:(NSZone *)zone; @end
9@protocol NSCoding  - (void)encodeWithCoder:(NSCoder *)aCoder; @end
10@protocol NSMutableCopying  - (id)mutableCopyWithZone:(NSZone *)zone; @end
11@interface NSObject <NSObject> {}
12+(id)alloc;
13-(id)init;
14-(id)autorelease;
15-(id)copy;
16-(id)retain;
17@end
18@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>
19- (NSUInteger)length;
20-(id)initWithFormat:(NSString *)f,...;
21-(BOOL)isEqualToString:(NSString *)s;
22+ (id)string;
23@end
24
25@interface Test1 : NSObject {
26  NSString *text;
27}
28-(id)myMethod;
29-(id)myMethodWithY:(int)Y withX:(int)X;
30
31@property (nonatomic, assign) NSString *text;
32@end
33
34@implementation Test1
35
36@synthesize text;
37
38-(id)myMethod {
39  Test1 *cell = [[[Test1 alloc] init] autorelease];
40
41  NSString *string1 = [[NSString alloc] initWithFormat:@"test %f", 0.0]; // No warning: this function is not analized.
42  cell.text = string1;
43
44  return cell;
45}
46
47-(id)myMethodWithY:(int)Y withX:(int)X {
48  Test1 *cell = [[[Test1 alloc] init] autorelease];
49
50  NSString *string1 = [[NSString alloc] initWithFormat:@"test %f %d", 0.0, X+Y]; // expected-warning {{Potential leak}}
51  cell.text = string1;
52
53  return cell;
54}
55
56@end
57