1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.cocoa.RetainCount -analyzer-config ipa=dynamic-bifurcate -verify %s
3 typedef signed char BOOL;
4 typedef struct objc_class *Class;
5 typedef struct objc_object {
8 @protocol NSObject - (BOOL)isEqual:(id)object; @end
9 @interface NSObject <NSObject> {}
12 - (oneway void)release;
18 - (oneway void)release;
21 @interface SelfStaysLive : NSObject
25 @implementation SelfStaysLive
31 void selfStaysLive(void) {
32 SelfStaysLive *foo = [[SelfStaysLive alloc] init];
36 // Test that retain release checker warns on leaks and use-after-frees when
37 // self init is not enabled.
39 @interface ParentOfCell : NSObject
40 - (id)initWithInt: (int)inInt;
42 @interface Cell : ParentOfCell{
45 - (id)initWithInt: (int)inInt;
46 + (void)testOverRelease;
52 - (id) initWithInt: (int)inInt {
53 [super initWithInt: inInt];
54 self.x = inInt; // no-warning
55 return self; // Self Init checker would produce a warning here.
57 + (void) testOverRelease {
58 Cell *sharedCell3 = [[Cell alloc] initWithInt: 3];
59 [sharedCell3 release];
60 [sharedCell3 release]; // expected-warning {{Reference-counted object is used after it is released}}
63 Cell *sharedCell4 = [[Cell alloc] initWithInt: 3]; // expected-warning {{leak}}
67 // We should stop tracking some objects even when we inline the call.
68 // Specialically, the objects passed into calls with delegate and callback
71 typedef void (*ReleaseCallbackTy) (DelegateTest *c);
73 @interface Delegate : NSObject
76 @interface DelegateTest : NSObject {
79 // Object initialized with a delagate which could potentially release it.
80 - (id)initWithDelegate: (id) d;
82 - (void) setDelegate: (id) d;
84 // Releases object through callback.
85 + (void)updateObject:(DelegateTest*)obj WithCallback:(ReleaseCallbackTy)rc;
87 + (void)test: (Delegate *)d;
89 @property (assign) Delegate* myDel;
92 void releaseObj(DelegateTest *c);
94 // Releases object through callback.
95 void updateObject(DelegateTest *c, ReleaseCallbackTy rel) {
99 @implementation DelegateTest
102 - (id) initWithDelegate: (id) d {
103 if ((self = [super init]))
108 - (void) setDelegate: (id) d {
112 + (void)updateObject:(DelegateTest*)obj WithCallback:(ReleaseCallbackTy)rc {
116 + (void) test: (Delegate *)d {
117 DelegateTest *obj1 = [[DelegateTest alloc] initWithDelegate: d]; // no-warning
118 DelegateTest *obj2 = [[DelegateTest alloc] init]; // no-warning
119 DelegateTest *obj3 = [[DelegateTest alloc] init]; // no-warning
120 updateObject(obj2, releaseObj);
121 [DelegateTest updateObject: obj3
122 WithCallback: releaseObj];
123 DelegateTest *obj4 = [[DelegateTest alloc] init]; // no-warning
124 [obj4 setDelegate: d];