blob: e0ce28b919c1b04b99d9cd560b7f0d430248c578 [file] [log] [blame]
Anna Zaks5bf5c2e2012-09-26 18:55:16 +00001// 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 Zaksb087bbf2012-09-27 19:45:08 +000045 SomeInvalidationImplementingObject *Obj1;
46 SomeInvalidationImplementingObject *Obj2;
Anna Zaks5bf5c2e2012-09-26 18:55:16 +000047 SomeInvalidationImplementingObject *Obj3;
48 SomeInvalidationImplementingObject *_Prop1;
49 SomeInvalidationImplementingObject *_Prop4;
50 SomeInvalidationImplementingObject *_propIvar;
Anna Zaksb087bbf2012-09-27 19:45:08 +000051 Invalidation1Class *MultipleProtocols;
52 Invalidation2Class *MultInheritance;
53
Anna Zaks5bf5c2e2012-09-26 18:55:16 +000054 // 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];
Anna Zaksb087bbf2012-09-27 19:45:08 +0000106}// expected-warning {{Instance variable Obj1 needs to be invalidated}}
107 // expected-warning@-1 {{Instance variable Obj2 needs to be invalidated}}
108 // expected-warning@-2 {{Instance variable MultipleProtocols needs to be invalidated}}
109 // expected-warning@-3 {{Instance variable MultInheritance needs to be invalidated}}
Anna Zaks5bf5c2e2012-09-26 18:55:16 +0000110@end