diff options
Diffstat (limited to 'clang/test/Analysis/PR2978.m')
| -rw-r--r-- | clang/test/Analysis/PR2978.m | 70 |
1 files changed, 56 insertions, 14 deletions
diff --git a/clang/test/Analysis/PR2978.m b/clang/test/Analysis/PR2978.m index 2067b3e85af..bb0fc414566 100644 --- a/clang/test/Analysis/PR2978.m +++ b/clang/test/Analysis/PR2978.m @@ -5,7 +5,7 @@ @interface NSObject - (void)release; -- dealloc; +- (void)dealloc; @end @interface MyClass : NSObject { @@ -19,8 +19,14 @@ id _M; id _P; id _Q; + id _R; + id _S; id _V; id _W; + + MyClass *_other; + + id _nonPropertyIvar; } @property(retain) id X; @property(retain) id Y; @@ -29,8 +35,13 @@ @property(weak) id L; @property(readonly) id N; @property(retain) id M; -@property(weak) id P; // expected-warning {{'_P' instance variable in 'MyClass' was not retained by a synthesized property but was released in 'dealloc'}} +@property(weak) id P; @property(weak) id Q; +@property(retain) id R; +@property(weak, readonly) id S; + +@property(assign, readonly) id T; // Shadowed in class extension +@property(assign) id U; @property(retain) id V; @property(retain) id W; @@ -38,36 +49,67 @@ -(void) setO: (id) arg; @end +@interface MyClass () +// Shadows T to make it readwrite internally but readonly externally. +@property(assign, readwrite) id T; +@end + @implementation MyClass @synthesize X = _X; -@synthesize Y = _Y; // expected-warning{{The '_Y' instance variable in 'MyClass' was retained by a synthesized property but was not released in 'dealloc'}} -@synthesize Z = _Z; // expected-warning{{The '_Z' instance variable in 'MyClass' was not retained by a synthesized property but was released in 'dealloc'}} +@synthesize Y = _Y; +@synthesize Z = _Z; @synthesize K = _K; -@synthesize L = _L; // no-warning -@synthesize N = _N; // no-warning +@synthesize L = _L; +@synthesize N = _N; @synthesize M = _M; -@synthesize Q = _Q; // expected-warning {{'_Q' instance variable in 'MyClass' was not retained by a synthesized property but was released in 'dealloc'}} +@synthesize Q = _Q; +@synthesize R = _R; @synthesize V = _V; -@synthesize W = _W; // expected-warning{{The '_W' instance variable in 'MyClass' was retained by a synthesized property but was not released in 'dealloc'}} +@synthesize W = _W; -(id) O{ return 0; } -(void) setO:(id)arg { } -- (id)dealloc + +-(void) releaseInHelper { + [_R release]; // no-warning + _R = @"Hi"; +} + +- (void)dealloc { + [_X release]; - [_Z release]; + [_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 [_N release]; - + 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 - self.O = 0; // no-warning - [_Q release]; + [_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'}} + self.P = 0; + + [self releaseInHelper]; + + [_nonPropertyIvar release]; // no-warning + + // Silly, but not an error. + if (!_U) + [_U release]; + [super dealloc]; - return 0; + // 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]'}} + } @end |

