Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -analyze -warn-objc-missing-dealloc %s -verify |
Ted Kremenek | 997c155 | 2008-10-30 15:19:43 +0000 | [diff] [blame] | 2 | |
| 3 | // Tests for the checker which checks missing/extra ivar 'release' calls |
| 4 | // in dealloc. |
| 5 | |
| 6 | @interface NSObject |
| 7 | - (void)release; |
Steve Naroff | 87d3ef0 | 2008-11-17 22:29:32 +0000 | [diff] [blame] | 8 | - dealloc; |
Ted Kremenek | 997c155 | 2008-10-30 15:19:43 +0000 | [diff] [blame] | 9 | @end |
| 10 | |
| 11 | @interface MyClass : NSObject { |
| 12 | @private |
| 13 | id _X; |
| 14 | id _Y; |
| 15 | id _Z; |
| 16 | id _K; |
| 17 | id _N; |
| 18 | id _M; |
| 19 | id _V; |
| 20 | id _W; |
| 21 | } |
| 22 | @property(retain) id X; |
| 23 | @property(retain) id Y; |
| 24 | @property(assign) id Z; |
| 25 | @property(assign) id K; |
Fariborz Jahanian | 567c8df | 2008-12-06 01:12:43 +0000 | [diff] [blame] | 26 | @property(readonly) id N; |
Ted Kremenek | 997c155 | 2008-10-30 15:19:43 +0000 | [diff] [blame] | 27 | @property(retain) id M; |
| 28 | @property(retain) id V; |
| 29 | @property(retain) id W; |
Ted Kremenek | ccb55e3 | 2008-10-30 23:00:13 +0000 | [diff] [blame] | 30 | -(id) O; |
| 31 | -(void) setO: (id) arg; |
Ted Kremenek | 997c155 | 2008-10-30 15:19:43 +0000 | [diff] [blame] | 32 | @end |
| 33 | |
| 34 | @implementation MyClass |
| 35 | @synthesize X = _X; |
| 36 | @synthesize Y = _Y; // expected-warning{{The '_Y' instance variable was retained by a synthesized property but wasn't released in 'dealloc'}} |
| 37 | @synthesize Z = _Z; // expected-warning{{The '_Z' instance variable was not retained by a synthesized property but was released in 'dealloc'}} |
| 38 | @synthesize K = _K; |
| 39 | @synthesize N = _N; |
| 40 | @synthesize M = _M; |
| 41 | @synthesize V = _V; |
| 42 | @synthesize W = _W; // expected-warning{{The '_W' instance variable was retained by a synthesized property but wasn't released in 'dealloc'}} |
| 43 | |
Ted Kremenek | ccb55e3 | 2008-10-30 23:00:13 +0000 | [diff] [blame] | 44 | -(id) O{ return 0; } |
| 45 | -(void) setO:(id)arg { } |
| 46 | |
Fariborz Jahanian | b33f3ad | 2009-05-01 20:07:12 +0000 | [diff] [blame] | 47 | - (id)dealloc |
Ted Kremenek | 997c155 | 2008-10-30 15:19:43 +0000 | [diff] [blame] | 48 | { |
| 49 | [_X release]; |
| 50 | [_Z release]; |
| 51 | [_N release]; |
| 52 | |
| 53 | self.M = 0; // This will release '_M' |
| 54 | [self setV:0]; // This will release '_V' |
| 55 | [self setW:@"newW"]; // This will release '_W', but retain the new value |
Ted Kremenek | ccb55e3 | 2008-10-30 23:00:13 +0000 | [diff] [blame] | 56 | self.O = 0; // no-warning |
Ted Kremenek | 997c155 | 2008-10-30 15:19:43 +0000 | [diff] [blame] | 57 | [super dealloc]; |
Mike Stump | 431e4d3 | 2009-07-21 18:52:41 +0000 | [diff] [blame] | 58 | return 0; |
Ted Kremenek | 997c155 | 2008-10-30 15:19:43 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @end |
| 62 | |