aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis/objc_invalidation.m
blob: e0ce28b919c1b04b99d9cd560b7f0d430248c578 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.osx.cocoa.InstanceVariableInvalidation -fobjc-default-synthesize-properties -verify %s

@protocol NSObject
@end
@interface NSObject <NSObject> {}
+(id)alloc;
+(id)new;
-(id)init;
-(id)autorelease;
-(id)copy;
- (Class)class;
-(id)retain;
@end

@protocol Invalidation1 <NSObject> 
- (void) invalidate __attribute__((annotate("objc_instance_variable_invalidator")));
@end 

@protocol Invalidation2 <NSObject> 
- (void) invalidate __attribute__((annotate("objc_instance_variable_invalidator")));
@end 

@protocol Invalidation3 <NSObject>
- (void) invalidate __attribute__((annotate("objc_instance_variable_invalidator")));
@end

@interface Invalidation2Class <Invalidation2>
@end

@interface Invalidation1Class <Invalidation1>
@end

@interface SomeInvalidationImplementingObject: NSObject <Invalidation3, Invalidation2> {
  SomeInvalidationImplementingObject *ObjA;
}
@end

@implementation SomeInvalidationImplementingObject
- (void)invalidate{
  ObjA = 0;
}
@end

@interface SomeSubclassInvalidatableObject : SomeInvalidationImplementingObject {
  SomeInvalidationImplementingObject *Obj1; 
  SomeInvalidationImplementingObject *Obj2;
  SomeInvalidationImplementingObject *Obj3;
  SomeInvalidationImplementingObject *_Prop1;
  SomeInvalidationImplementingObject *_Prop4;
  SomeInvalidationImplementingObject *_propIvar;
  Invalidation1Class *MultipleProtocols;
  Invalidation2Class *MultInheritance; 
  
  // No warnings on these.
  NSObject *NObj1;
  NSObject *NObj2;
  NSObject *_NProp1;
  NSObject *_NpropIvar;
}

@property (assign) SomeInvalidationImplementingObject* Prop0;
@property (nonatomic, assign) SomeInvalidationImplementingObject* Prop1;
@property (assign) SomeInvalidationImplementingObject* Prop2;
@property (assign) SomeInvalidationImplementingObject* Prop3;
@property (assign) SomeInvalidationImplementingObject* Prop4;
@property (assign) NSObject* NProp0;
@property (nonatomic, assign) NSObject* NProp1;
@property (assign) NSObject* NProp2;

-(void)setProp1: (SomeInvalidationImplementingObject*) InO;
-(void)setNProp1: (NSObject*) InO;

-(void)invalidate;

@end

@implementation SomeSubclassInvalidatableObject

@synthesize Prop2 = _propIvar;
@synthesize Prop3;

- (void) setProp1: (SomeInvalidationImplementingObject*) InObj {
  _Prop1 = InObj;
}

- (void) setProp4: (SomeInvalidationImplementingObject*) InObj {
  _Prop4 = InObj;
}
- (SomeInvalidationImplementingObject*) Prop4 {
  return _Prop4;
}

@synthesize NProp2 = _NpropIvar;

- (void) setNProp1: (NSObject*) InObj {
  _NProp1 = InObj;
}

- (void) invalidate {
   [Obj3 invalidate];
   self.Prop1 = 0;
   [self setProp2:0];
   [self setProp3:0];
   self.Prop4 = 0;
   [super invalidate];
}// expected-warning {{Instance variable Obj1 needs to be invalidated}}
 // expected-warning@-1 {{Instance variable Obj2 needs to be invalidated}}
 // expected-warning@-2 {{Instance variable MultipleProtocols needs to be invalidated}}
 // expected-warning@-3 {{Instance variable MultInheritance needs to be invalidated}}
@end