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 { |
Anna Zaks | b087bbf | 2012-09-27 19:45:08 +0000 | [diff] [blame] | 45 | SomeInvalidationImplementingObject *Obj1; |
| 46 | SomeInvalidationImplementingObject *Obj2; |
Anna Zaks | 5bf5c2e | 2012-09-26 18:55:16 +0000 | [diff] [blame] | 47 | SomeInvalidationImplementingObject *Obj3; |
| 48 | SomeInvalidationImplementingObject *_Prop1; |
| 49 | SomeInvalidationImplementingObject *_Prop4; |
| 50 | SomeInvalidationImplementingObject *_propIvar; |
Anna Zaks | b087bbf | 2012-09-27 19:45:08 +0000 | [diff] [blame] | 51 | Invalidation1Class *MultipleProtocols; |
| 52 | Invalidation2Class *MultInheritance; |
Anna Zaks | 377945c | 2012-09-27 21:57:14 +0000 | [diff] [blame] | 53 | SomeInvalidationImplementingObject *_Prop5; // invalidate via getter method |
Anna Zaks | b087bbf | 2012-09-27 19:45:08 +0000 | [diff] [blame] | 54 | |
Anna Zaks | 5bf5c2e | 2012-09-26 18:55:16 +0000 | [diff] [blame] | 55 | // No warnings on these. |
| 56 | NSObject *NObj1; |
| 57 | NSObject *NObj2; |
| 58 | NSObject *_NProp1; |
| 59 | NSObject *_NpropIvar; |
| 60 | } |
| 61 | |
| 62 | @property (assign) SomeInvalidationImplementingObject* Prop0; |
| 63 | @property (nonatomic, assign) SomeInvalidationImplementingObject* Prop1; |
| 64 | @property (assign) SomeInvalidationImplementingObject* Prop2; |
| 65 | @property (assign) SomeInvalidationImplementingObject* Prop3; |
| 66 | @property (assign) SomeInvalidationImplementingObject* Prop4; |
Anna Zaks | 377945c | 2012-09-27 21:57:14 +0000 | [diff] [blame] | 67 | @property (assign) SomeInvalidationImplementingObject* Prop5; |
| 68 | @property (assign) SomeInvalidationImplementingObject *SynthIvarProp; |
| 69 | |
| 70 | |
Anna Zaks | 5bf5c2e | 2012-09-26 18:55:16 +0000 | [diff] [blame] | 71 | @property (assign) NSObject* NProp0; |
| 72 | @property (nonatomic, assign) NSObject* NProp1; |
| 73 | @property (assign) NSObject* NProp2; |
| 74 | |
| 75 | -(void)setProp1: (SomeInvalidationImplementingObject*) InO; |
| 76 | -(void)setNProp1: (NSObject*) InO; |
| 77 | |
| 78 | -(void)invalidate; |
| 79 | |
| 80 | @end |
| 81 | |
| 82 | @implementation SomeSubclassInvalidatableObject |
| 83 | |
| 84 | @synthesize Prop2 = _propIvar; |
| 85 | @synthesize Prop3; |
| 86 | |
| 87 | - (void) setProp1: (SomeInvalidationImplementingObject*) InObj { |
| 88 | _Prop1 = InObj; |
| 89 | } |
| 90 | |
| 91 | - (void) setProp4: (SomeInvalidationImplementingObject*) InObj { |
| 92 | _Prop4 = InObj; |
| 93 | } |
| 94 | - (SomeInvalidationImplementingObject*) Prop4 { |
| 95 | return _Prop4; |
| 96 | } |
| 97 | |
| 98 | @synthesize NProp2 = _NpropIvar; |
| 99 | |
| 100 | - (void) setNProp1: (NSObject*) InObj { |
| 101 | _NProp1 = InObj; |
| 102 | } |
| 103 | |
| 104 | - (void) invalidate { |
| 105 | [Obj3 invalidate]; |
Anna Zaks | 377945c | 2012-09-27 21:57:14 +0000 | [diff] [blame] | 106 | self.Prop0 = 0; |
Anna Zaks | 5bf5c2e | 2012-09-26 18:55:16 +0000 | [diff] [blame] | 107 | self.Prop1 = 0; |
| 108 | [self setProp2:0]; |
| 109 | [self setProp3:0]; |
| 110 | self.Prop4 = 0; |
Anna Zaks | 377945c | 2012-09-27 21:57:14 +0000 | [diff] [blame] | 111 | [[self Prop5] invalidate]; |
Anna Zaks | 5bf5c2e | 2012-09-26 18:55:16 +0000 | [diff] [blame] | 112 | [super invalidate]; |
Anna Zaks | b087bbf | 2012-09-27 19:45:08 +0000 | [diff] [blame] | 113 | }// expected-warning {{Instance variable Obj1 needs to be invalidated}} |
| 114 | // expected-warning@-1 {{Instance variable Obj2 needs to be invalidated}} |
| 115 | // expected-warning@-2 {{Instance variable MultipleProtocols needs to be invalidated}} |
| 116 | // expected-warning@-3 {{Instance variable MultInheritance needs to be invalidated}} |
Anna Zaks | 377945c | 2012-09-27 21:57:14 +0000 | [diff] [blame] | 117 | // expected-warning@-4 {{Property SynthIvarProp needs to be invalidated}} |
Anna Zaks | 5bf5c2e | 2012-09-26 18:55:16 +0000 | [diff] [blame] | 118 | @end |