brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · deede9d Raw
68 lines · plain
1// RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.cocoa.RetainCount,osx.cocoa.SelfInit -analyzer-config ipa=dynamic-bifurcate -verify %s2 3typedef signed char BOOL;4typedef struct objc_class *Class;5typedef struct objc_object {6    Class isa;7} *id;8@protocol NSObject  - (BOOL)isEqual:(id)object; @end9@interface NSObject <NSObject> {}10+(id)alloc;11+(id)new;12- (oneway void)release;13-(id)init;14-(id)autorelease;15-(id)copy;16- (Class)class;17-(id)retain;18@end19 20// We do not want to overhelm user with error messages in case they forgot to 21// assign to self and check that the result of [super init] is non-nil. So 22// stop tracking the receiver of init with respect to Retain Release checker.  23@interface ParentOfCell : NSObject24- (id)initWithInt: (int)inInt;25@end26@interface Cell : ParentOfCell{27  int x;28}29- (id)init;30+ (void)test;31@property int x;32@end33@implementation Cell34@synthesize x;35- (id) init {36  [super init];37  self.x = 3; // no-warning 38  return self; // expected-warning {{Returning 'self' while it is not set to the result of '[(super or self)}} 39}40- (id) initWithInt: (int)inInt {41  [super initWithInt: inInt];42  self.x = inInt; // no-warning 43  return self; // expected-warning {{Returning 'self' while it is not set to the result of '[(super or self)}} 44}45- (id) init2 {46  [self init]; // The call [self init] is inlined. We will warn inside the inlined body.47  self.x = 2; // no-warning 48  return self; 49}50 51- (id) initWithIntGood: (int)inInt {52    if (self = [super initWithInt: inInt]) {53      self.x = inInt; 54    }55    return self; 56}57+ (void) test {58  Cell *sharedCell1 = [[Cell alloc] init];59  [sharedCell1 release];60  Cell *sharedCell2 = [[Cell alloc] initWithInt: 3];61  [sharedCell2 release];62  Cell *sharedCell3 = [[Cell alloc] initWithIntGood: 3];63  [sharedCell3 release];64}65 66@end67 68