2016-03-03 05:50:54 +08:00
|
|
|
// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.core,osx.cocoa.Dealloc %s -verify
|
2008-10-30 23:19:43 +08:00
|
|
|
|
|
|
|
// Tests for the checker which checks missing/extra ivar 'release' calls
|
|
|
|
// in dealloc.
|
|
|
|
|
|
|
|
@interface NSObject
|
|
|
|
- (void)release;
|
2016-02-26 05:15:16 +08:00
|
|
|
- (void)dealloc;
|
2008-10-30 23:19:43 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
@interface MyClass : NSObject {
|
|
|
|
@private
|
|
|
|
id _X;
|
|
|
|
id _Y;
|
|
|
|
id _Z;
|
|
|
|
id _K;
|
2016-01-27 09:41:58 +08:00
|
|
|
id _L;
|
2008-10-30 23:19:43 +08:00
|
|
|
id _N;
|
|
|
|
id _M;
|
2016-02-12 06:13:20 +08:00
|
|
|
id _P;
|
|
|
|
id _Q;
|
2016-02-26 05:15:16 +08:00
|
|
|
id _R;
|
|
|
|
id _S;
|
2008-10-30 23:19:43 +08:00
|
|
|
id _V;
|
|
|
|
id _W;
|
2016-02-26 05:15:16 +08:00
|
|
|
|
|
|
|
MyClass *_other;
|
|
|
|
|
|
|
|
id _nonPropertyIvar;
|
2008-10-30 23:19:43 +08:00
|
|
|
}
|
|
|
|
@property(retain) id X;
|
2016-10-16 08:30:08 +08:00
|
|
|
@property(retain) id Y;
|
|
|
|
@property(assign) id Z;
|
2008-10-30 23:19:43 +08:00
|
|
|
@property(assign) id K;
|
2016-01-27 09:41:58 +08:00
|
|
|
@property(weak) id L;
|
2008-12-06 09:12:43 +08:00
|
|
|
@property(readonly) id N;
|
2008-10-30 23:19:43 +08:00
|
|
|
@property(retain) id M;
|
2016-02-26 05:15:16 +08:00
|
|
|
@property(weak) id P;
|
2016-10-16 08:30:08 +08:00
|
|
|
@property(weak) id Q;
|
2016-02-26 05:15:16 +08:00
|
|
|
@property(retain) id R;
|
2016-10-16 08:30:08 +08:00
|
|
|
@property(weak, readonly) id S;
|
2016-02-26 05:15:16 +08:00
|
|
|
|
|
|
|
@property(assign, readonly) id T; // Shadowed in class extension
|
|
|
|
@property(assign) id U;
|
2016-02-12 06:13:20 +08:00
|
|
|
|
2008-10-30 23:19:43 +08:00
|
|
|
@property(retain) id V;
|
2016-10-16 08:30:08 +08:00
|
|
|
@property(retain) id W;
|
2008-10-31 07:00:13 +08:00
|
|
|
-(id) O;
|
|
|
|
-(void) setO: (id) arg;
|
2008-10-30 23:19:43 +08:00
|
|
|
@end
|
|
|
|
|
2016-02-26 05:15:16 +08:00
|
|
|
@interface MyClass ()
|
|
|
|
// Shadows T to make it readwrite internally but readonly externally.
|
|
|
|
@property(assign, readwrite) id T;
|
|
|
|
@end
|
|
|
|
|
2008-10-30 23:19:43 +08:00
|
|
|
@implementation MyClass
|
|
|
|
@synthesize X = _X;
|
2016-10-16 08:30:08 +08:00
|
|
|
@synthesize Y = _Y;
|
|
|
|
@synthesize Z = _Z;
|
2008-10-30 23:19:43 +08:00
|
|
|
@synthesize K = _K;
|
2016-02-26 05:15:16 +08:00
|
|
|
@synthesize L = _L;
|
|
|
|
@synthesize N = _N;
|
2008-10-30 23:19:43 +08:00
|
|
|
@synthesize M = _M;
|
2016-10-16 08:30:08 +08:00
|
|
|
@synthesize Q = _Q;
|
2016-02-26 05:15:16 +08:00
|
|
|
@synthesize R = _R;
|
2008-10-30 23:19:43 +08:00
|
|
|
@synthesize V = _V;
|
2016-10-16 08:30:08 +08:00
|
|
|
@synthesize W = _W;
|
2008-10-30 23:19:43 +08:00
|
|
|
|
2008-10-31 07:00:13 +08:00
|
|
|
-(id) O{ return 0; }
|
|
|
|
-(void) setO:(id)arg { }
|
|
|
|
|
2016-02-26 05:15:16 +08:00
|
|
|
|
|
|
|
-(void) releaseInHelper {
|
|
|
|
[_R release]; // no-warning
|
|
|
|
_R = @"Hi";
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
2008-10-30 23:19:43 +08:00
|
|
|
{
|
2016-02-26 05:15:16 +08:00
|
|
|
|
2008-10-30 23:19:43 +08:00
|
|
|
[_X release];
|
2016-02-26 05:15:16 +08:00
|
|
|
[_Z release]; // expected-warning{{The '_Z' ivar in 'MyClass' was synthesized for an assign, readwrite property but was released in 'dealloc'}}
|
|
|
|
[_T release]; // no-warning
|
|
|
|
|
|
|
|
[_other->_Z release]; // no-warning
|
2008-10-30 23:19:43 +08:00
|
|
|
[_N release];
|
2016-02-26 05:15:16 +08:00
|
|
|
|
2008-10-30 23:19:43 +08:00
|
|
|
self.M = 0; // This will release '_M'
|
|
|
|
[self setV:0]; // This will release '_V'
|
|
|
|
[self setW:@"newW"]; // This will release '_W', but retain the new value
|
2016-02-12 06:13:20 +08:00
|
|
|
|
2016-02-26 05:15:16 +08:00
|
|
|
[_S release]; // expected-warning {{The '_S' ivar in 'MyClass' was synthesized for a weak property but was released in 'dealloc'}}
|
|
|
|
|
|
|
|
self.O = 0; // no-warning
|
|
|
|
|
|
|
|
[_Q release]; // expected-warning {{The '_Q' ivar in 'MyClass' was synthesized for a weak property but was released in 'dealloc'}}
|
|
|
|
|
2016-02-12 06:13:20 +08:00
|
|
|
self.P = 0;
|
2016-02-26 05:15:16 +08:00
|
|
|
|
|
|
|
[self releaseInHelper];
|
|
|
|
|
|
|
|
[_nonPropertyIvar release]; // no-warning
|
|
|
|
|
|
|
|
// Silly, but not an error.
|
|
|
|
if (!_U)
|
|
|
|
[_U release];
|
|
|
|
|
2008-10-30 23:19:43 +08:00
|
|
|
[super dealloc];
|
2016-02-26 05:15:16 +08:00
|
|
|
// expected-warning@-1{{The '_Y' ivar in 'MyClass' was retained by a synthesized property but not released before '[super dealloc]'}}
|
|
|
|
// expected-warning@-2{{The '_W' ivar in 'MyClass' was retained by a synthesized property but not released before '[super dealloc]'}}
|
|
|
|
|
2008-10-30 23:19:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|