1// RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.cocoa.RetainCount,osx.cocoa.SelfInit -analyzer-config ipa=dynamic-bifurcate -verify %s
2
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; @end
9@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@end
19
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// radar://12115830
24@interface ParentOfCell : NSObject
25- (id)initWithInt: (int)inInt;
26@end
27@interface Cell : ParentOfCell{
28  int x;
29}
30- (id)init;
31+ (void)test;
32@property int x;
33@end
34@implementation Cell
35@synthesize x;
36- (id) init {
37  [super init];
38  self.x = 3; // no-warning
39  return self; // expected-warning {{Returning 'self' while it is not set to the result of '[(super or self)}}
40}
41- (id) initWithInt: (int)inInt {
42  [super initWithInt: inInt];
43  self.x = inInt; // no-warning
44  return self; // expected-warning {{Returning 'self' while it is not set to the result of '[(super or self)}}
45}
46- (id) init2 {
47  [self init]; // The call [self init] is inlined. We will warn inside the inlined body.
48  self.x = 2; // no-warning
49  return self;
50}
51
52- (id) initWithIntGood: (int)inInt {
53    if (self = [super initWithInt: inInt]) {
54      self.x = inInt;
55    }
56    return self;
57}
58+ (void) test {
59  Cell *sharedCell1 = [[Cell alloc] init];
60  [sharedCell1 release];
61  Cell *sharedCell2 = [[Cell alloc] initWithInt: 3];
62  [sharedCell2 release];
63  Cell *sharedCell3 = [[Cell alloc] initWithIntGood: 3];
64  [sharedCell3 release];
65}
66
67@end
68
69