Anna Zaks | 5bf5c2e | 2012-09-26 18:55:16 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.osx.cocoa.InstanceVariableInvalidation -fobjc-default-synthesize-properties -verify %s |
| 2 | |
| 3 | @protocol NSObject |
| 4 | @end |
| 5 | @interface NSObject <NSObject> {} |
| 6 | +(id)alloc; |
| 7 | +(id)new; |
| 8 | -(id)init; |
| 9 | -(id)autorelease; |
| 10 | -(id)copy; |
| 11 | - (Class)class; |
| 12 | -(id)retain; |
| 13 | @end |
| 14 | |
| 15 | @protocol Invalidation1 <NSObject> |
| 16 | - (void) invalidate __attribute__((annotate("objc_instance_variable_invalidator"))); |
| 17 | @end |
| 18 | |
| 19 | @protocol Invalidation2 <NSObject> |
| 20 | - (void) invalidate __attribute__((annotate("objc_instance_variable_invalidator"))); |
| 21 | @end |
| 22 | |
| 23 | @protocol Invalidation3 <NSObject> |
| 24 | - (void) invalidate __attribute__((annotate("objc_instance_variable_invalidator"))); |
| 25 | @end |
| 26 | |
| 27 | @interface Invalidation2Class <Invalidation2> |
| 28 | @end |
| 29 | |
| 30 | @interface Invalidation1Class <Invalidation1> |
| 31 | @end |
| 32 | |
| 33 | @interface SomeInvalidationImplementingObject: NSObject <Invalidation3, Invalidation2> { |
| 34 | SomeInvalidationImplementingObject *ObjA; |
| 35 | } |
| 36 | @end |
| 37 | |
| 38 | @implementation SomeInvalidationImplementingObject |
| 39 | - (void)invalidate{ |
| 40 | ObjA = 0; |
| 41 | } |
| 42 | @end |
| 43 | |
| 44 | @interface SomeSubclassInvalidatableObject : SomeInvalidationImplementingObject { |
| 45 | SomeInvalidationImplementingObject *Obj1; // expected-warning{{Ivar needs to be invalidated}} |
| 46 | SomeInvalidationImplementingObject *Obj2; // expected-warning{{Ivar needs to be invalidated}} |
| 47 | SomeInvalidationImplementingObject *Obj3; |
| 48 | SomeInvalidationImplementingObject *_Prop1; |
| 49 | SomeInvalidationImplementingObject *_Prop4; |
| 50 | SomeInvalidationImplementingObject *_propIvar; |
| 51 | Invalidation1Class *MultipleProtocols; // expected-warning{{Ivar needs to be invalidated}} |
| 52 | Invalidation2Class *MultInheritance; // expected-warning{{Ivar needs to be invalidated}} |
| 53 | |
| 54 | // No warnings on these. |
| 55 | NSObject *NObj1; |
| 56 | NSObject *NObj2; |
| 57 | NSObject *_NProp1; |
| 58 | NSObject *_NpropIvar; |
| 59 | } |
| 60 | |
| 61 | @property (assign) SomeInvalidationImplementingObject* Prop0; |
| 62 | @property (nonatomic, assign) SomeInvalidationImplementingObject* Prop1; |
| 63 | @property (assign) SomeInvalidationImplementingObject* Prop2; |
| 64 | @property (assign) SomeInvalidationImplementingObject* Prop3; |
| 65 | @property (assign) SomeInvalidationImplementingObject* Prop4; |
| 66 | @property (assign) NSObject* NProp0; |
| 67 | @property (nonatomic, assign) NSObject* NProp1; |
| 68 | @property (assign) NSObject* NProp2; |
| 69 | |
| 70 | -(void)setProp1: (SomeInvalidationImplementingObject*) InO; |
| 71 | -(void)setNProp1: (NSObject*) InO; |
| 72 | |
| 73 | -(void)invalidate; |
| 74 | |
| 75 | @end |
| 76 | |
| 77 | @implementation SomeSubclassInvalidatableObject |
| 78 | |
| 79 | @synthesize Prop2 = _propIvar; |
| 80 | @synthesize Prop3; |
| 81 | |
| 82 | - (void) setProp1: (SomeInvalidationImplementingObject*) InObj { |
| 83 | _Prop1 = InObj; |
| 84 | } |
| 85 | |
| 86 | - (void) setProp4: (SomeInvalidationImplementingObject*) InObj { |
| 87 | _Prop4 = InObj; |
| 88 | } |
| 89 | - (SomeInvalidationImplementingObject*) Prop4 { |
| 90 | return _Prop4; |
| 91 | } |
| 92 | |
| 93 | @synthesize NProp2 = _NpropIvar; |
| 94 | |
| 95 | - (void) setNProp1: (NSObject*) InObj { |
| 96 | _NProp1 = InObj; |
| 97 | } |
| 98 | |
| 99 | - (void) invalidate { |
| 100 | [Obj3 invalidate]; |
| 101 | self.Prop1 = 0; |
| 102 | [self setProp2:0]; |
| 103 | [self setProp3:0]; |
| 104 | self.Prop4 = 0; |
| 105 | [super invalidate]; |
| 106 | } |
| 107 | @end |