Home | History | Annotate | Download | only in Analysis
      1 // RUN: %clang_cc1 -analyze -analyzer-checker=alpha.core -analyzer-checker=alpha.osx.cocoa.Dealloc %s -verify
      2 
      3 // Tests for the checker which checks missing/extra ivar 'release' calls 
      4 // in dealloc.
      5 
      6 @interface NSObject
      7 - (void)release;
      8 - dealloc;
      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;
     26 @property(readonly) id N;
     27 @property(retain) id M;
     28 @property(retain) id V;
     29 @property(retain) id W;
     30 -(id) O;
     31 -(void) setO: (id) arg;
     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 
     44 -(id) O{ return 0; }
     45 -(void) setO:(id)arg { }
     46 
     47 - (id)dealloc
     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
     56   self.O = 0; // no-warning  
     57   [super dealloc];
     58   return 0;
     59 }
     60 
     61 @end
     62 
     63