annotate clang/test/Analysis/DeallocUseAfterFreeErrors.m @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.cocoa.SuperDealloc,debug.ExprInspection -analyzer-output=text -verify %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 void clang_analyzer_warnIfReached();
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 #define nil ((id)0)
anatofuz
parents:
diff changeset
6
anatofuz
parents:
diff changeset
7 typedef unsigned long NSUInteger;
anatofuz
parents:
diff changeset
8 @protocol NSObject
anatofuz
parents:
diff changeset
9 - (instancetype)retain;
anatofuz
parents:
diff changeset
10 - (oneway void)release;
anatofuz
parents:
diff changeset
11 @end
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 @interface NSObject <NSObject> { }
anatofuz
parents:
diff changeset
14 - (void)dealloc;
anatofuz
parents:
diff changeset
15 - (instancetype)init;
anatofuz
parents:
diff changeset
16 @end
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 typedef struct objc_selector *SEL;
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 //===------------------------------------------------------------------------===
anatofuz
parents:
diff changeset
21 // <rdar://problem/6953275>
anatofuz
parents:
diff changeset
22 // Check that 'self' is not referenced after calling '[super dealloc]'.
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 @interface SuperDeallocThenReleaseIvarClass : NSObject {
anatofuz
parents:
diff changeset
25 NSObject *_ivar;
anatofuz
parents:
diff changeset
26 }
anatofuz
parents:
diff changeset
27 @end
anatofuz
parents:
diff changeset
28
anatofuz
parents:
diff changeset
29 @implementation SuperDeallocThenReleaseIvarClass
anatofuz
parents:
diff changeset
30 - (instancetype)initWithIvar:(NSObject *)ivar {
anatofuz
parents:
diff changeset
31 self = [super init];
anatofuz
parents:
diff changeset
32 if (!self)
anatofuz
parents:
diff changeset
33 return nil;
anatofuz
parents:
diff changeset
34 _ivar = [ivar retain];
anatofuz
parents:
diff changeset
35 return self;
anatofuz
parents:
diff changeset
36 }
anatofuz
parents:
diff changeset
37 - (void)dealloc {
anatofuz
parents:
diff changeset
38 [super dealloc]; // expected-note {{[super dealloc] called here}}
anatofuz
parents:
diff changeset
39 [_ivar release]; // expected-warning {{Use of instance variable '_ivar' after 'self' has been deallocated}}
anatofuz
parents:
diff changeset
40 // expected-note@-1 {{Use of instance variable '_ivar' after 'self' has been deallocated}}
anatofuz
parents:
diff changeset
41 }
anatofuz
parents:
diff changeset
42 @end
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 @interface SuperDeallocThenAssignNilToIvarClass : NSObject {
anatofuz
parents:
diff changeset
45 NSObject *_delegate;
anatofuz
parents:
diff changeset
46 }
anatofuz
parents:
diff changeset
47 @end
anatofuz
parents:
diff changeset
48
anatofuz
parents:
diff changeset
49 @implementation SuperDeallocThenAssignNilToIvarClass
anatofuz
parents:
diff changeset
50 - (instancetype)initWithDelegate:(NSObject *)delegate {
anatofuz
parents:
diff changeset
51 self = [super init];
anatofuz
parents:
diff changeset
52 if (!self)
anatofuz
parents:
diff changeset
53 return nil;
anatofuz
parents:
diff changeset
54 _delegate = delegate;
anatofuz
parents:
diff changeset
55 return self;
anatofuz
parents:
diff changeset
56 }
anatofuz
parents:
diff changeset
57 - (void)dealloc {
anatofuz
parents:
diff changeset
58 [super dealloc]; // expected-note {{[super dealloc] called here}}
anatofuz
parents:
diff changeset
59 _delegate = nil; // expected-warning {{Use of instance variable '_delegate' after 'self' has been deallocated}}
anatofuz
parents:
diff changeset
60 // expected-note@-1 {{Use of instance variable '_delegate' after 'self' has been deallocated}}
anatofuz
parents:
diff changeset
61 }
anatofuz
parents:
diff changeset
62 @end
anatofuz
parents:
diff changeset
63
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65 struct SomeStruct {
anatofuz
parents:
diff changeset
66 int f;
anatofuz
parents:
diff changeset
67 };
anatofuz
parents:
diff changeset
68
anatofuz
parents:
diff changeset
69 @interface SuperDeallocThenAssignIvarField : NSObject {
anatofuz
parents:
diff changeset
70 struct SomeStruct _s;
anatofuz
parents:
diff changeset
71 }
anatofuz
parents:
diff changeset
72 @end
anatofuz
parents:
diff changeset
73
anatofuz
parents:
diff changeset
74 @implementation SuperDeallocThenAssignIvarField
anatofuz
parents:
diff changeset
75 - (void)dealloc {
anatofuz
parents:
diff changeset
76 [super dealloc]; // expected-note {{[super dealloc] called here}}
anatofuz
parents:
diff changeset
77 _s.f = 7; // expected-warning {{Use of instance variable '_s' after 'self' has been deallocated}}
anatofuz
parents:
diff changeset
78 // expected-note@-1 {{Use of instance variable '_s' after 'self' has been deallocated}}
anatofuz
parents:
diff changeset
79 }
anatofuz
parents:
diff changeset
80 @end
anatofuz
parents:
diff changeset
81
anatofuz
parents:
diff changeset
82 @interface OtherClassWithIvar {
anatofuz
parents:
diff changeset
83 @public
anatofuz
parents:
diff changeset
84 int _otherIvar;
anatofuz
parents:
diff changeset
85 }
anatofuz
parents:
diff changeset
86 @end;
anatofuz
parents:
diff changeset
87
anatofuz
parents:
diff changeset
88 @interface SuperDeallocThenAssignIvarIvar : NSObject {
anatofuz
parents:
diff changeset
89 OtherClassWithIvar *_ivar;
anatofuz
parents:
diff changeset
90 }
anatofuz
parents:
diff changeset
91 @end
anatofuz
parents:
diff changeset
92
anatofuz
parents:
diff changeset
93 @implementation SuperDeallocThenAssignIvarIvar
anatofuz
parents:
diff changeset
94 - (void)dealloc {
anatofuz
parents:
diff changeset
95 [super dealloc]; // expected-note {{[super dealloc] called here}}
anatofuz
parents:
diff changeset
96 _ivar->_otherIvar = 7; // expected-warning {{Use of instance variable '_ivar' after 'self' has been deallocated}}
anatofuz
parents:
diff changeset
97 // expected-note@-1 {{Use of instance variable '_ivar' after 'self' has been deallocated}}
anatofuz
parents:
diff changeset
98 }
anatofuz
parents:
diff changeset
99 @end
anatofuz
parents:
diff changeset
100
anatofuz
parents:
diff changeset
101 @interface SuperDeallocThenAssignSelfIvar : NSObject {
anatofuz
parents:
diff changeset
102 NSObject *_ivar;
anatofuz
parents:
diff changeset
103 }
anatofuz
parents:
diff changeset
104 @end
anatofuz
parents:
diff changeset
105
anatofuz
parents:
diff changeset
106 @implementation SuperDeallocThenAssignSelfIvar
anatofuz
parents:
diff changeset
107 - (void)dealloc {
anatofuz
parents:
diff changeset
108 [super dealloc]; // expected-note {{[super dealloc] called here}}
anatofuz
parents:
diff changeset
109 self->_ivar = nil; // expected-warning {{Use of instance variable '_ivar' after 'self' has been deallocated}}
anatofuz
parents:
diff changeset
110 // expected-note@-1 {{Use of instance variable '_ivar' after 'self' has been deallocated}}
anatofuz
parents:
diff changeset
111 }
anatofuz
parents:
diff changeset
112 @end
anatofuz
parents:
diff changeset
113
anatofuz
parents:
diff changeset
114 @interface SuperDeallocThenReleasePropertyClass : NSObject { }
anatofuz
parents:
diff changeset
115 @property (retain) NSObject *ivar;
anatofuz
parents:
diff changeset
116 @end
anatofuz
parents:
diff changeset
117
anatofuz
parents:
diff changeset
118 @implementation SuperDeallocThenReleasePropertyClass
anatofuz
parents:
diff changeset
119 - (instancetype)initWithProperty:(NSObject *)ivar {
anatofuz
parents:
diff changeset
120 self = [super init];
anatofuz
parents:
diff changeset
121 if (!self)
anatofuz
parents:
diff changeset
122 return nil;
anatofuz
parents:
diff changeset
123 self.ivar = ivar;
anatofuz
parents:
diff changeset
124 return self;
anatofuz
parents:
diff changeset
125 }
anatofuz
parents:
diff changeset
126 - (void)dealloc {
anatofuz
parents:
diff changeset
127 [super dealloc]; // expected-note {{[super dealloc] called here}}
anatofuz
parents:
diff changeset
128 self.ivar = nil; // expected-warning {{Use of 'self' after it has been deallocated}}
anatofuz
parents:
diff changeset
129 // expected-note@-1 {{Use of 'self' after it has been deallocated}}
anatofuz
parents:
diff changeset
130 }
anatofuz
parents:
diff changeset
131 @end
anatofuz
parents:
diff changeset
132
anatofuz
parents:
diff changeset
133 @interface SuperDeallocThenAssignNilToPropertyClass : NSObject { }
anatofuz
parents:
diff changeset
134 @property (assign) NSObject *delegate;
anatofuz
parents:
diff changeset
135 @end
anatofuz
parents:
diff changeset
136
anatofuz
parents:
diff changeset
137 @implementation SuperDeallocThenAssignNilToPropertyClass
anatofuz
parents:
diff changeset
138 - (instancetype)initWithDelegate:(NSObject *)delegate {
anatofuz
parents:
diff changeset
139 self = [super init];
anatofuz
parents:
diff changeset
140 if (!self)
anatofuz
parents:
diff changeset
141 return nil;
anatofuz
parents:
diff changeset
142 self.delegate = delegate;
anatofuz
parents:
diff changeset
143 return self;
anatofuz
parents:
diff changeset
144 }
anatofuz
parents:
diff changeset
145 - (void)dealloc {
anatofuz
parents:
diff changeset
146 [super dealloc]; // expected-note {{[super dealloc] called here}}
anatofuz
parents:
diff changeset
147 self.delegate = nil; // expected-warning {{Use of 'self' after it has been deallocated}}
anatofuz
parents:
diff changeset
148 // expected-note@-1 {{Use of 'self' after it has been deallocated}}
anatofuz
parents:
diff changeset
149 }
anatofuz
parents:
diff changeset
150 @end
anatofuz
parents:
diff changeset
151
anatofuz
parents:
diff changeset
152 @interface SuperDeallocThenCallInstanceMethodClass : NSObject { }
anatofuz
parents:
diff changeset
153 - (void)_invalidate;
anatofuz
parents:
diff changeset
154 @end
anatofuz
parents:
diff changeset
155
anatofuz
parents:
diff changeset
156 @implementation SuperDeallocThenCallInstanceMethodClass
anatofuz
parents:
diff changeset
157 - (void)_invalidate {
anatofuz
parents:
diff changeset
158 }
anatofuz
parents:
diff changeset
159 - (void)dealloc {
anatofuz
parents:
diff changeset
160 [super dealloc]; // expected-note {{[super dealloc] called here}}
anatofuz
parents:
diff changeset
161 [self _invalidate]; // expected-warning {{Use of 'self' after it has been deallocated}}
anatofuz
parents:
diff changeset
162 // expected-note@-1 {{Use of 'self' after it has been deallocated}}
anatofuz
parents:
diff changeset
163 }
anatofuz
parents:
diff changeset
164 @end
anatofuz
parents:
diff changeset
165
anatofuz
parents:
diff changeset
166 @interface SuperDeallocThenCallNonObjectiveCMethodClass : NSObject { }
anatofuz
parents:
diff changeset
167 @end
anatofuz
parents:
diff changeset
168
anatofuz
parents:
diff changeset
169 static void _invalidate(NSObject *object) {
anatofuz
parents:
diff changeset
170 (void)object;
anatofuz
parents:
diff changeset
171 }
anatofuz
parents:
diff changeset
172
anatofuz
parents:
diff changeset
173 @implementation SuperDeallocThenCallNonObjectiveCMethodClass
anatofuz
parents:
diff changeset
174 - (void)dealloc {
anatofuz
parents:
diff changeset
175 [super dealloc]; // expected-note {{[super dealloc] called here}}
anatofuz
parents:
diff changeset
176 _invalidate(self); // expected-warning {{Use of 'self' after it has been deallocated}}
anatofuz
parents:
diff changeset
177 // expected-note@-1 {{Use of 'self' after it has been deallocated}}
anatofuz
parents:
diff changeset
178 }
anatofuz
parents:
diff changeset
179 @end
anatofuz
parents:
diff changeset
180
anatofuz
parents:
diff changeset
181 @interface SuperDeallocThenCallObjectiveClassMethodClass : NSObject { }
anatofuz
parents:
diff changeset
182 @end
anatofuz
parents:
diff changeset
183
anatofuz
parents:
diff changeset
184 @implementation SuperDeallocThenCallObjectiveClassMethodClass
anatofuz
parents:
diff changeset
185 + (void) invalidate:(id)arg; {
anatofuz
parents:
diff changeset
186 }
anatofuz
parents:
diff changeset
187
anatofuz
parents:
diff changeset
188 - (void)dealloc {
anatofuz
parents:
diff changeset
189 [super dealloc]; // expected-note {{[super dealloc] called here}}
anatofuz
parents:
diff changeset
190 [SuperDeallocThenCallObjectiveClassMethodClass invalidate:self]; // expected-warning {{Use of 'self' after it has been deallocated}}
anatofuz
parents:
diff changeset
191 // expected-note@-1 {{Use of 'self' after it has been deallocated}}
anatofuz
parents:
diff changeset
192 }
anatofuz
parents:
diff changeset
193 @end
anatofuz
parents:
diff changeset
194
anatofuz
parents:
diff changeset
195 @interface TwoSuperDeallocCallsClass : NSObject {
anatofuz
parents:
diff changeset
196 NSObject *_ivar;
anatofuz
parents:
diff changeset
197 }
anatofuz
parents:
diff changeset
198 - (void)_invalidate;
anatofuz
parents:
diff changeset
199 @end
anatofuz
parents:
diff changeset
200
anatofuz
parents:
diff changeset
201 @implementation TwoSuperDeallocCallsClass
anatofuz
parents:
diff changeset
202 - (void)_invalidate {
anatofuz
parents:
diff changeset
203 }
anatofuz
parents:
diff changeset
204 - (void)dealloc {
anatofuz
parents:
diff changeset
205 if (_ivar) { // expected-note {{Assuming the condition is false}} expected-note {{Taking false branch}}
anatofuz
parents:
diff changeset
206 [_ivar release];
anatofuz
parents:
diff changeset
207 [super dealloc];
anatofuz
parents:
diff changeset
208 return;
anatofuz
parents:
diff changeset
209 }
anatofuz
parents:
diff changeset
210 [super dealloc]; // expected-note {{[super dealloc] called here}}
anatofuz
parents:
diff changeset
211 [self _invalidate]; // expected-warning {{Use of 'self' after it has been deallocated}}
anatofuz
parents:
diff changeset
212 // expected-note@-1 {{Use of 'self' after it has been deallocated}}
anatofuz
parents:
diff changeset
213 }
anatofuz
parents:
diff changeset
214 @end
anatofuz
parents:
diff changeset
215
anatofuz
parents:
diff changeset
216 //===------------------------------------------------------------------------===
anatofuz
parents:
diff changeset
217 // Warn about calling [super dealloc] twice due to missing return statement.
anatofuz
parents:
diff changeset
218
anatofuz
parents:
diff changeset
219 @interface MissingReturnCausesDoubleSuperDeallocClass : NSObject {
anatofuz
parents:
diff changeset
220 NSObject *_ivar;
anatofuz
parents:
diff changeset
221 }
anatofuz
parents:
diff changeset
222 @end
anatofuz
parents:
diff changeset
223
anatofuz
parents:
diff changeset
224 @implementation MissingReturnCausesDoubleSuperDeallocClass
anatofuz
parents:
diff changeset
225 - (void)dealloc {
anatofuz
parents:
diff changeset
226 if (_ivar) { // expected-note {{Assuming the condition is true}} expected-note {{Taking true branch}}
anatofuz
parents:
diff changeset
227 [_ivar release];
anatofuz
parents:
diff changeset
228 [super dealloc]; // expected-note {{[super dealloc] called here}}
anatofuz
parents:
diff changeset
229 // return;
anatofuz
parents:
diff changeset
230 }
anatofuz
parents:
diff changeset
231 [super dealloc]; // expected-warning{{[super dealloc] should not be called multiple times}}
anatofuz
parents:
diff changeset
232 // expected-note@-1{{[super dealloc] should not be called multiple times}}
anatofuz
parents:
diff changeset
233 }
anatofuz
parents:
diff changeset
234 @end
anatofuz
parents:
diff changeset
235
anatofuz
parents:
diff changeset
236 //===------------------------------------------------------------------------===
anatofuz
parents:
diff changeset
237 // Warn about calling [super dealloc] twice in two different methods.
anatofuz
parents:
diff changeset
238
anatofuz
parents:
diff changeset
239 @interface SuperDeallocInOtherMethodClass : NSObject {
anatofuz
parents:
diff changeset
240 NSObject *_ivar;
anatofuz
parents:
diff changeset
241 }
anatofuz
parents:
diff changeset
242 - (void)_cleanup;
anatofuz
parents:
diff changeset
243 @end
anatofuz
parents:
diff changeset
244
anatofuz
parents:
diff changeset
245 @implementation SuperDeallocInOtherMethodClass
anatofuz
parents:
diff changeset
246 - (void)_cleanup {
anatofuz
parents:
diff changeset
247 [_ivar release];
anatofuz
parents:
diff changeset
248 [super dealloc]; // expected-note {{[super dealloc] called here}}
anatofuz
parents:
diff changeset
249 }
anatofuz
parents:
diff changeset
250 - (void)dealloc {
anatofuz
parents:
diff changeset
251 [self _cleanup]; // expected-note {{Calling '_cleanup'}}
anatofuz
parents:
diff changeset
252 //expected-note@-1 {{Returning from '_cleanup'}}
anatofuz
parents:
diff changeset
253 [super dealloc]; // expected-warning {{[super dealloc] should not be called multiple times}}
anatofuz
parents:
diff changeset
254 // expected-note@-1 {{[super dealloc] should not be called multiple times}}
anatofuz
parents:
diff changeset
255 }
anatofuz
parents:
diff changeset
256 @end
anatofuz
parents:
diff changeset
257
anatofuz
parents:
diff changeset
258 //===------------------------------------------------------------------------===
anatofuz
parents:
diff changeset
259 // Do not warn about calling [super dealloc] recursively for different objects
anatofuz
parents:
diff changeset
260 // of the same type with custom retain counting.
anatofuz
parents:
diff changeset
261 //
anatofuz
parents:
diff changeset
262 // A class that contains an ivar of itself with custom retain counting (such
anatofuz
parents:
diff changeset
263 // as provided by _OBJC_SUPPORTED_INLINE_REFCNT_WITH_DEALLOC2MAIN) can generate
anatofuz
parents:
diff changeset
264 // a false positive that [super dealloc] is called twice if each object instance
anatofuz
parents:
diff changeset
265 // is not tracked separately by the checker. This test case is just a simple
anatofuz
parents:
diff changeset
266 // approximation to trigger the false positive.
anatofuz
parents:
diff changeset
267
anatofuz
parents:
diff changeset
268 @class ClassWithOwnIvarInstanceClass;
anatofuz
parents:
diff changeset
269 @interface ClassWithOwnIvarInstanceClass : NSObject {
anatofuz
parents:
diff changeset
270 ClassWithOwnIvarInstanceClass *_ivar;
anatofuz
parents:
diff changeset
271 NSUInteger _retainCount;
anatofuz
parents:
diff changeset
272 }
anatofuz
parents:
diff changeset
273 @end
anatofuz
parents:
diff changeset
274
anatofuz
parents:
diff changeset
275 @implementation ClassWithOwnIvarInstanceClass
anatofuz
parents:
diff changeset
276 - (instancetype)retain {
anatofuz
parents:
diff changeset
277 ++_retainCount;
anatofuz
parents:
diff changeset
278 return self;
anatofuz
parents:
diff changeset
279 }
anatofuz
parents:
diff changeset
280 - (oneway void)release {
anatofuz
parents:
diff changeset
281 --_retainCount;
anatofuz
parents:
diff changeset
282 if (!_retainCount)
anatofuz
parents:
diff changeset
283 [self dealloc];
anatofuz
parents:
diff changeset
284 }
anatofuz
parents:
diff changeset
285 - (void)dealloc {
anatofuz
parents:
diff changeset
286 [_ivar release];
anatofuz
parents:
diff changeset
287 [super dealloc]; // no warning: different instances of same class
anatofuz
parents:
diff changeset
288 }
anatofuz
parents:
diff changeset
289 @end
anatofuz
parents:
diff changeset
290
anatofuz
parents:
diff changeset
291 //===------------------------------------------------------------------------===
anatofuz
parents:
diff changeset
292 // Do not warn about calling [super dealloc] twice if +dealloc is a class
anatofuz
parents:
diff changeset
293 // method.
anatofuz
parents:
diff changeset
294
anatofuz
parents:
diff changeset
295 @interface SuperDeallocClassMethodIgnoredClass : NSObject { }
anatofuz
parents:
diff changeset
296 + (void)dealloc;
anatofuz
parents:
diff changeset
297 @end
anatofuz
parents:
diff changeset
298
anatofuz
parents:
diff changeset
299 @implementation SuperDeallocClassMethodIgnoredClass
anatofuz
parents:
diff changeset
300 + (void)dealloc { }
anatofuz
parents:
diff changeset
301 @end
anatofuz
parents:
diff changeset
302
anatofuz
parents:
diff changeset
303 @interface SuperDeallocClassMethodIgnoredSubClass : NSObject { }
anatofuz
parents:
diff changeset
304 + (void)dealloc;
anatofuz
parents:
diff changeset
305 @end
anatofuz
parents:
diff changeset
306
anatofuz
parents:
diff changeset
307 @implementation SuperDeallocClassMethodIgnoredSubClass
anatofuz
parents:
diff changeset
308 + (void)dealloc {
anatofuz
parents:
diff changeset
309 [super dealloc];
anatofuz
parents:
diff changeset
310 [super dealloc]; // no warning: class method
anatofuz
parents:
diff changeset
311 }
anatofuz
parents:
diff changeset
312 @end
anatofuz
parents:
diff changeset
313
anatofuz
parents:
diff changeset
314 //===------------------------------------------------------------------------===
anatofuz
parents:
diff changeset
315 // Do not warn about calling [super dealloc] twice if when the analyzer has
anatofuz
parents:
diff changeset
316 // inlined the call to its super deallocator.
anatofuz
parents:
diff changeset
317
anatofuz
parents:
diff changeset
318 @interface SuperClassCallingSuperDealloc : NSObject {
anatofuz
parents:
diff changeset
319 NSObject *_ivar;
anatofuz
parents:
diff changeset
320 }
anatofuz
parents:
diff changeset
321 @end
anatofuz
parents:
diff changeset
322
anatofuz
parents:
diff changeset
323 @implementation SuperClassCallingSuperDealloc
anatofuz
parents:
diff changeset
324 - (void)dealloc; {
anatofuz
parents:
diff changeset
325 [_ivar release]; // no-warning
anatofuz
parents:
diff changeset
326
anatofuz
parents:
diff changeset
327 [super dealloc];
anatofuz
parents:
diff changeset
328 }
anatofuz
parents:
diff changeset
329 @end
anatofuz
parents:
diff changeset
330
anatofuz
parents:
diff changeset
331 @interface SubclassCallingSuperDealloc : SuperClassCallingSuperDealloc
anatofuz
parents:
diff changeset
332 @end
anatofuz
parents:
diff changeset
333
anatofuz
parents:
diff changeset
334 @implementation SubclassCallingSuperDealloc
anatofuz
parents:
diff changeset
335 - (void)dealloc; {
anatofuz
parents:
diff changeset
336 [super dealloc];
anatofuz
parents:
diff changeset
337 }
anatofuz
parents:
diff changeset
338 @end
anatofuz
parents:
diff changeset
339
anatofuz
parents:
diff changeset
340 //===------------------------------------------------------------------------===
anatofuz
parents:
diff changeset
341 // Treat calling [super dealloc] twice as as a sink.
anatofuz
parents:
diff changeset
342
anatofuz
parents:
diff changeset
343 @interface CallingSuperDeallocTwiceIsSink : NSObject
anatofuz
parents:
diff changeset
344 @end
anatofuz
parents:
diff changeset
345
anatofuz
parents:
diff changeset
346 @implementation CallingSuperDeallocTwiceIsSink
anatofuz
parents:
diff changeset
347 - (void)dealloc; {
anatofuz
parents:
diff changeset
348 [super dealloc]; // expected-note {{[super dealloc] called here}}
anatofuz
parents:
diff changeset
349 [super dealloc]; // expected-warning {{[super dealloc] should not be called multiple times}}
anatofuz
parents:
diff changeset
350 // expected-note@-1 {{[super dealloc] should not be called multiple times}}
anatofuz
parents:
diff changeset
351
anatofuz
parents:
diff changeset
352 clang_analyzer_warnIfReached(); // no-warning
anatofuz
parents:
diff changeset
353 }
anatofuz
parents:
diff changeset
354 @end
anatofuz
parents:
diff changeset
355
anatofuz
parents:
diff changeset
356
anatofuz
parents:
diff changeset
357 //===------------------------------------------------------------------------===
anatofuz
parents:
diff changeset
358 // Test path notes with intervening method call on self.
anatofuz
parents:
diff changeset
359
anatofuz
parents:
diff changeset
360 @interface InterveningMethodCallOnSelf : NSObject
anatofuz
parents:
diff changeset
361 @end
anatofuz
parents:
diff changeset
362
anatofuz
parents:
diff changeset
363 @implementation InterveningMethodCallOnSelf
anatofuz
parents:
diff changeset
364 - (void)anotherMethod {
anatofuz
parents:
diff changeset
365 }
anatofuz
parents:
diff changeset
366
anatofuz
parents:
diff changeset
367 - (void)dealloc; {
anatofuz
parents:
diff changeset
368 [super dealloc]; // expected-note {{[super dealloc] called here}}
anatofuz
parents:
diff changeset
369 [self anotherMethod]; // expected-warning {{Use of 'self' after it has been deallocated}}
anatofuz
parents:
diff changeset
370 // expected-note@-1 {{Use of 'self' after it has been deallocated}}
anatofuz
parents:
diff changeset
371 [super dealloc];
anatofuz
parents:
diff changeset
372 }
anatofuz
parents:
diff changeset
373 @end