57 lines · plain
1// RUN: %clang_analyze_cc1 -analyze-function="-[Test1 myMethodWithY:withX:]" -analyzer-checker=core,osx.cocoa.RetainCount -verify %s2 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; @end8@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end9@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end10@protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end11@interface NSObject <NSObject> {}12+(id)alloc;13-(id)init;14-(id)autorelease;15-(id)copy;16-(id)retain;17@end18@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>19- (NSUInteger)length;20-(id)initWithFormat:(NSString *)f,...;21-(BOOL)isEqualToString:(NSString *)s;22+ (id)string;23@end24 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@end33 34@implementation Test135 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 analyzed.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@end57