blob: a53fc1e56624015242542c63e6eef71b694320af [file] [log] [blame]
Dominic Chen184c6242017-03-03 18:02:02 +00001// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -analyzer-checker=core,osx.cocoa.NilArg,osx.cocoa.RetainCount,alpha.core -analyzer-store=region -verify -Wno-objc-root-class %s
2// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -analyzer-checker=core,osx.cocoa.NilArg,osx.cocoa.RetainCount,alpha.core -analyzer-store=region -analyzer-config mode=shallow -verify -Wno-objc-root-class %s
3// RUN: %clang_analyze_cc1 -DTEST_64 -triple x86_64-apple-darwin10 -analyzer-checker=core,osx.cocoa.NilArg,osx.cocoa.RetainCount,alpha.core -analyzer-store=region -verify -Wno-objc-root-class %s
4// RUN: %clang_analyze_cc1 -DOSATOMIC_USE_INLINED -triple i386-apple-darwin10 -analyzer-checker=core,osx.cocoa.NilArg,osx.cocoa.RetainCount,alpha.core -analyzer-store=region -verify -Wno-objc-root-class %s
Ted Kremenekbbe61112008-06-16 20:37:30 +00005
6//===----------------------------------------------------------------------===//
7// The following code is reduced using delta-debugging from
8// Foundation.h (Mac OS X).
9//
10// It includes the basic definitions for the test cases below.
11// Not directly including Foundation.h directly makes this test case
12// both svelte and portable to non-Mac platforms.
13//===----------------------------------------------------------------------===//
14
Ted Kremenek3abc41f2009-10-15 01:40:34 +000015#ifdef TEST_64
16typedef long long int64_t;
17_Bool OSAtomicCompareAndSwap64Barrier( int64_t __oldValue, int64_t __newValue, volatile int64_t *__theValue );
18#define COMPARE_SWAP_BARRIER OSAtomicCompareAndSwap64Barrier
19typedef int64_t intptr_t;
20#else
Ted Kremenekbcf597d2009-04-29 16:03:59 +000021typedef int int32_t;
Ted Kremenek3abc41f2009-10-15 01:40:34 +000022_Bool OSAtomicCompareAndSwap32Barrier( int32_t __oldValue, int32_t __newValue, volatile int32_t *__theValue );
23#define COMPARE_SWAP_BARRIER OSAtomicCompareAndSwap32Barrier
24typedef int32_t intptr_t;
25#endif
26
Ted Kremenekbbe61112008-06-16 20:37:30 +000027typedef const void * CFTypeRef;
28typedef const struct __CFString * CFStringRef;
29typedef const struct __CFAllocator * CFAllocatorRef;
30extern const CFAllocatorRef kCFAllocatorDefault;
31extern CFTypeRef CFRetain(CFTypeRef cf);
Ted Kremeneka8e8bc22009-04-21 20:01:03 +000032void CFRelease(CFTypeRef cf);
Ted Kremenekbbe61112008-06-16 20:37:30 +000033typedef const struct __CFDictionary * CFDictionaryRef;
Ted Kremenek62d4c122008-12-17 21:50:35 +000034const void *CFDictionaryGetValue(CFDictionaryRef theDict, const void *key);
Ted Kremenekbbe61112008-06-16 20:37:30 +000035extern CFStringRef CFStringCreateWithFormat(CFAllocatorRef alloc, CFDictionaryRef formatOptions, CFStringRef format, ...);
36typedef signed char BOOL;
37typedef int NSInteger;
38typedef unsigned int NSUInteger;
39@class NSString, Protocol;
40extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
41typedef NSInteger NSComparisonResult;
42typedef struct _NSZone NSZone;
43@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
44@protocol NSObject
45- (BOOL)isEqual:(id)object;
46- (oneway void)release;
Ted Kremenek62d4c122008-12-17 21:50:35 +000047- (id)retain;
Ted Kremenekdc7853c2009-05-11 15:26:06 +000048- (id)autorelease;
Ted Kremenekbbe61112008-06-16 20:37:30 +000049@end
50@protocol NSCopying
51- (id)copyWithZone:(NSZone *)zone;
52@end
53@protocol NSMutableCopying
54- (id)mutableCopyWithZone:(NSZone *)zone;
55@end
56@protocol NSCoding
57- (void)encodeWithCoder:(NSCoder *)aCoder;
58@end
59@interface NSObject <NSObject> {}
60- (id)init;
61+ (id)alloc;
62@end
63extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
64typedef struct {} NSFastEnumerationState;
65@protocol NSFastEnumeration
66- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;
67@end
68@class NSString;
69typedef struct _NSRange {} NSRange;
70@interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
71- (NSUInteger)count;
72@end
73@interface NSMutableArray : NSArray
74- (void)addObject:(id)anObject;
75- (id)initWithCapacity:(NSUInteger)numItems;
76@end
77typedef unsigned short unichar;
78@class NSData, NSArray, NSDictionary, NSCharacterSet, NSData, NSURL, NSError, NSLocale;
79typedef NSUInteger NSStringCompareOptions;
80@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding> - (NSUInteger)length;
81- (NSComparisonResult)compare:(NSString *)string;
82- (NSComparisonResult)compare:(NSString *)string options:(NSStringCompareOptions)mask;
83- (NSComparisonResult)compare:(NSString *)string options:(NSStringCompareOptions)mask range:(NSRange)compareRange;
84- (NSComparisonResult)compare:(NSString *)string options:(NSStringCompareOptions)mask range:(NSRange)compareRange locale:(id)locale;
85- (NSComparisonResult)caseInsensitiveCompare:(NSString *)string;
86- (NSArray *)componentsSeparatedByCharactersInSet:(NSCharacterSet *)separator;
Ted Kremenekf27110f2009-04-23 19:11:35 +000087+ (id)stringWithFormat:(NSString *)format, ... __attribute__((format(__NSString__, 1, 2)));
Ted Kremenekbbe61112008-06-16 20:37:30 +000088@end
89@interface NSSimpleCString : NSString {} @end
90@interface NSConstantString : NSSimpleCString @end
91extern void *_NSConstantStringClassReference;
92
93//===----------------------------------------------------------------------===//
94// Test cases.
95//===----------------------------------------------------------------------===//
96
97NSComparisonResult f1(NSString* s) {
98 NSString *aString = 0;
Richard Trieu553b2b22011-12-15 00:38:15 +000099 return [s compare:aString]; // expected-warning {{Argument to 'NSString' method 'compare:' cannot be nil}}
Ted Kremenekbbe61112008-06-16 20:37:30 +0000100}
101
102NSComparisonResult f2(NSString* s) {
103 NSString *aString = 0;
Richard Trieu553b2b22011-12-15 00:38:15 +0000104 return [s caseInsensitiveCompare:aString]; // expected-warning {{Argument to 'NSString' method 'caseInsensitiveCompare:' cannot be nil}}
Ted Kremenekbbe61112008-06-16 20:37:30 +0000105}
106
107NSComparisonResult f3(NSString* s, NSStringCompareOptions op) {
108 NSString *aString = 0;
Richard Trieu553b2b22011-12-15 00:38:15 +0000109 return [s compare:aString options:op]; // expected-warning {{Argument to 'NSString' method 'compare:options:' cannot be nil}}
Ted Kremenekbbe61112008-06-16 20:37:30 +0000110}
111
112NSComparisonResult f4(NSString* s, NSStringCompareOptions op, NSRange R) {
113 NSString *aString = 0;
Richard Trieu553b2b22011-12-15 00:38:15 +0000114 return [s compare:aString options:op range:R]; // expected-warning {{Argument to 'NSString' method 'compare:options:range:' cannot be nil}}
Ted Kremenekbbe61112008-06-16 20:37:30 +0000115}
116
117NSComparisonResult f5(NSString* s, NSStringCompareOptions op, NSRange R) {
118 NSString *aString = 0;
Richard Trieu553b2b22011-12-15 00:38:15 +0000119 return [s compare:aString options:op range:R locale:0]; // expected-warning {{Argument to 'NSString' method 'compare:options:range:locale:' cannot be nil}}
Ted Kremenekbbe61112008-06-16 20:37:30 +0000120}
121
Daniel Dunbar81f7f292008-08-05 00:07:51 +0000122NSArray *f6(NSString* s) {
Richard Trieu553b2b22011-12-15 00:38:15 +0000123 return [s componentsSeparatedByCharactersInSet:0]; // expected-warning {{Argument to 'NSString' method 'componentsSeparatedByCharactersInSet:' cannot be nil}}
Ted Kremenekbbe61112008-06-16 20:37:30 +0000124}
125
126NSString* f7(NSString* s1, NSString* s2, NSString* s3) {
127
Daniel Dunbar81f7f292008-08-05 00:07:51 +0000128 NSString* s4 = (NSString*)
Ted Kremenekfc5d0672009-02-04 23:49:09 +0000129 CFStringCreateWithFormat(kCFAllocatorDefault, 0, // expected-warning{{leak}}
Daniel Dunbar81f7f292008-08-05 00:07:51 +0000130 (CFStringRef) __builtin___CFStringMakeConstantString("%@ %@ (%@)"),
131 s1, s2, s3);
Ted Kremenekbbe61112008-06-16 20:37:30 +0000132
133 CFRetain(s4);
Ted Kremenekfc5d0672009-02-04 23:49:09 +0000134 return s4;
Ted Kremenekbbe61112008-06-16 20:37:30 +0000135}
136
137NSMutableArray* f8() {
138
139 NSString* s = [[NSString alloc] init];
140 NSMutableArray* a = [[NSMutableArray alloc] initWithCapacity:2];
141 [a addObject:s];
142 [s release]; // no-warning
143 return a;
144}
145
146void f9() {
147
148 NSString* s = [[NSString alloc] init];
149 NSString* q = s;
150 [s release];
151 [q release]; // expected-warning {{used after it is released}}
152}
153
154NSString* f10() {
Ted Kremenekbbe61112008-06-16 20:37:30 +0000155 static NSString* s = 0;
Ted Kremenekbbe61112008-06-16 20:37:30 +0000156 if (!s) s = [[NSString alloc] init];
Ted Kremenekbbe61112008-06-16 20:37:30 +0000157 return s; // no-warning
158}
159
Ted Kremenek62d4c122008-12-17 21:50:35 +0000160// Test case for regression reported in <rdar://problem/6452745>.
161// Essentially 's' should not be considered allocated on the false branch.
162// This exercises the 'EvalAssume' logic in GRTransferFuncs (CFRefCount.cpp).
163NSString* f11(CFDictionaryRef dict, const char* key) {
164 NSString* s = (NSString*) CFDictionaryGetValue(dict, key);
165 [s retain];
166 if (s) {
167 [s release];
168 }
Mike Stump79a9f202009-07-21 18:46:15 +0000169 return 0;
Ted Kremenek62d4c122008-12-17 21:50:35 +0000170}
171
Ted Kremenek021752a2008-12-18 23:40:58 +0000172// Test case for passing a tracked object by-reference to a function we
Ted Kremeneka8e8bc22009-04-21 20:01:03 +0000173// don't understand.
Ted Kremenek021752a2008-12-18 23:40:58 +0000174void unknown_function_f12(NSString** s);
175void f12() {
176 NSString *string = [[NSString alloc] init];
177 unknown_function_f12(&string); // no-warning
178}
179
Ted Kremeneka8e8bc22009-04-21 20:01:03 +0000180// Test double release of CFString (PR 4014).
181void f13(void) {
182 CFStringRef ref = CFStringCreateWithFormat(kCFAllocatorDefault, ((void*)0), ((CFStringRef) __builtin___CFStringMakeConstantString ("" "%d" "")), 100);
183 CFRelease(ref);
184 CFRelease(ref); // expected-warning{{Reference-counted object is used after it is released}}
185}
Ted Kremenek021752a2008-12-18 23:40:58 +0000186
Anders Carlsson3c50aea2011-03-08 20:05:26 +0000187@interface MyString : NSString
188@end
189
190void f14(MyString *s) {
Richard Trieu553b2b22011-12-15 00:38:15 +0000191 [s compare:0]; // expected-warning {{Argument to 'MyString' method 'compare:' cannot be nil}}
Anders Carlsson3c50aea2011-03-08 20:05:26 +0000192}
193
Ted Kremenekdc7853c2009-05-11 15:26:06 +0000194// Test regular use of -autorelease
195@interface TestAutorelease
196-(NSString*) getString;
197@end
198@implementation TestAutorelease
199-(NSString*) getString {
200 NSString *str = [[NSString alloc] init];
201 return [str autorelease]; // no-warning
202}
Ted Kremenek051a03d2009-05-13 07:12:33 +0000203- (void)m1
204{
205 NSString *s = [[NSString alloc] init]; // expected-warning{{leak}}
206 [s retain];
207 [s autorelease];
208}
209- (void)m2
210{
211 NSString *s = [[[NSString alloc] init] autorelease]; // expected-warning{{leak}}
212 [s retain];
213}
214- (void)m3
215{
216 NSString *s = [[[NSString alloc] init] autorelease];
217 [s retain];
218 [s autorelease];
219}
220- (void)m4
221{
222 NSString *s = [[NSString alloc] init]; // expected-warning{{leak}}
223 [s retain];
224}
225- (void)m5
226{
227 NSString *s = [[NSString alloc] init];
228 [s autorelease];
229}
Ted Kremenekdc7853c2009-05-11 15:26:06 +0000230@end
231
Ted Kremenekbbe61112008-06-16 20:37:30 +0000232@interface C1 : NSObject {}
233- (NSString*) getShared;
234+ (C1*) sharedInstance;
235@end
Ted Kremenek68b117f2008-07-03 15:37:02 +0000236@implementation C1 : NSObject {}
Ted Kremenekbbe61112008-06-16 20:37:30 +0000237- (NSString*) getShared {
238 static NSString* s = 0;
239 if (!s) s = [[NSString alloc] init];
240 return s; // no-warning
241}
242+ (C1 *)sharedInstance {
243 static C1 *sharedInstance = 0;
244 if (!sharedInstance) {
245 sharedInstance = [[C1 alloc] init];
246 }
247 return sharedInstance; // no-warning
248}
249@end
250
251@interface SharedClass : NSObject
252+ (id)sharedInstance;
Ted Kremenek1d92d2c2009-01-07 00:39:56 +0000253- (id)notShared;
Ted Kremenekbbe61112008-06-16 20:37:30 +0000254@end
Ted Kremenek1d92d2c2009-01-07 00:39:56 +0000255
Ted Kremenek68b117f2008-07-03 15:37:02 +0000256@implementation SharedClass
Ted Kremenekbbe61112008-06-16 20:37:30 +0000257
258- (id)_init {
259 if ((self = [super init])) {
260 NSLog(@"Bar");
261 }
262 return self;
263}
264
Ted Kremenek1d92d2c2009-01-07 00:39:56 +0000265- (id)notShared {
Ted Kremenek394dfeb2009-02-07 22:55:48 +0000266 return [[SharedClass alloc] _init]; // expected-warning{{leak}}
Ted Kremenek1d92d2c2009-01-07 00:39:56 +0000267}
268
Ted Kremenekbbe61112008-06-16 20:37:30 +0000269+ (id)sharedInstance {
270 static SharedClass *_sharedInstance = 0;
271 if (!_sharedInstance) {
272 _sharedInstance = [[SharedClass alloc] _init];
273 }
274 return _sharedInstance; // no-warning
275}
276@end
Ted Kremenek1d92d2c2009-01-07 00:39:56 +0000277
278id testSharedClassFromFunction() {
279 return [[SharedClass alloc] _init]; // no-warning
280}
281
Devin Coughlin7646ebe2016-03-28 23:55:58 +0000282#if !(defined(OSATOMIC_USE_INLINED) && OSATOMIC_USE_INLINED)
Ted Kremenekdf240002009-04-11 00:11:10 +0000283// Test OSCompareAndSwap
284_Bool OSAtomicCompareAndSwapPtr( void *__oldValue, void *__newValue, void * volatile *__theValue );
Ted Kremenek4531be12009-04-11 00:54:13 +0000285extern BOOL objc_atomicCompareAndSwapPtr(id predicate, id replacement, volatile id *objectLocation);
Devin Coughlin7646ebe2016-03-28 23:55:58 +0000286#else
287// Test that the body farm models are still used even when a body is available.
288_Bool opaque_OSAtomicCompareAndSwapPtr( void *__oldValue, void *__newValue, void * volatile *__theValue );
289_Bool OSAtomicCompareAndSwapPtr( void *__oldValue, void *__newValue, void * volatile *__theValue ) {
290 return opaque_OSAtomicCompareAndSwapPtr(__oldValue, __newValue, __theValue);
291}
Alexander Shaposhnikova1fead22016-09-23 20:49:01 +0000292// Test that the analyzer doesn't crash when the farm model is used.
293// The analyzer ignores the autosynthesized code.
294_Bool OSAtomicCompareAndSwapEmptyFunction( void *__oldValue, void *__newValue, void * volatile *__theValue ) {
295 return 0;
296}
Devin Coughlin7646ebe2016-03-28 23:55:58 +0000297extern BOOL opaque_objc_atomicCompareAndSwapPtr(id predicate, id replacement, volatile id *objectLocation);
298extern BOOL objc_atomicCompareAndSwapPtr(id predicate, id replacement, volatile id *objectLocation) {
299 return opaque_objc_atomicCompareAndSwapPtr(predicate, replacement, objectLocation);
300}
301#endif
Ted Kremenekdf240002009-04-11 00:11:10 +0000302
303void testOSCompareAndSwap() {
304 NSString *old = 0;
Ted Kremenek4531be12009-04-11 00:54:13 +0000305 NSString *s = [[NSString alloc] init]; // no-warning
Ted Kremenekdf240002009-04-11 00:11:10 +0000306 if (!OSAtomicCompareAndSwapPtr(0, s, (void**) &old))
307 [s release];
308 else
309 [old release];
310}
311
Ted Kremenek85739132009-12-09 23:29:55 +0000312void testOSCompareAndSwapXXBarrier_local() {
Ted Kremenekbcf597d2009-04-29 16:03:59 +0000313 NSString *old = 0;
314 NSString *s = [[NSString alloc] init]; // no-warning
Ted Kremenek3abc41f2009-10-15 01:40:34 +0000315 if (!COMPARE_SWAP_BARRIER((intptr_t) 0, (intptr_t) s, (intptr_t*) &old))
Ted Kremenekbcf597d2009-04-29 16:03:59 +0000316 [s release];
317 else
318 [old release];
319}
320
Ted Kremenek85739132009-12-09 23:29:55 +0000321void testOSCompareAndSwapXXBarrier_local_no_direct_release() {
Ted Kremenek3abc41f2009-10-15 01:40:34 +0000322 NSString *old = 0;
Zhongxing Xu1d153322009-12-09 08:32:57 +0000323 NSString *s = [[NSString alloc] init]; // no-warning
Ted Kremenek3abc41f2009-10-15 01:40:34 +0000324 if (!COMPARE_SWAP_BARRIER((intptr_t) 0, (intptr_t) s, (intptr_t*) &old))
325 return;
326 else
327 [old release];
328}
329
330int testOSCompareAndSwapXXBarrier_id(Class myclass, id xclass) {
331 if (COMPARE_SWAP_BARRIER(0, (intptr_t) myclass, (intptr_t*) &xclass))
Ted Kremenek70b943f2009-07-29 18:18:25 +0000332 return 1;
333 return 0;
Ted Kremenek3abc41f2009-10-15 01:40:34 +0000334}
Ted Kremenek70b943f2009-07-29 18:18:25 +0000335
Ted Kremenek85739132009-12-09 23:29:55 +0000336void test_objc_atomicCompareAndSwap_local() {
Ted Kremenek4531be12009-04-11 00:54:13 +0000337 NSString *old = 0;
338 NSString *s = [[NSString alloc] init]; // no-warning
339 if (!objc_atomicCompareAndSwapPtr(0, s, &old))
340 [s release];
341 else
342 [old release];
343}
344
Ted Kremenek85739132009-12-09 23:29:55 +0000345void test_objc_atomicCompareAndSwap_local_no_direct_release() {
Ted Kremenek3abc41f2009-10-15 01:40:34 +0000346 NSString *old = 0;
Zhongxing Xu1d153322009-12-09 08:32:57 +0000347 NSString *s = [[NSString alloc] init]; // no-warning
Ted Kremenek3abc41f2009-10-15 01:40:34 +0000348 if (!objc_atomicCompareAndSwapPtr(0, s, &old))
349 return;
350 else
351 [old release];
352}
353
Ted Kremenek85739132009-12-09 23:29:55 +0000354void test_objc_atomicCompareAndSwap_parameter(NSString **old) {
355 NSString *s = [[NSString alloc] init]; // no-warning
356 if (!objc_atomicCompareAndSwapPtr(0, s, old))
357 [s release];
358 else
359 [*old release];
360}
361
362void test_objc_atomicCompareAndSwap_parameter_no_direct_release(NSString **old) {
363 NSString *s = [[NSString alloc] init]; // expected-warning{{leak}}
364 if (!objc_atomicCompareAndSwapPtr(0, s, old))
365 return;
366 else
367 [*old release];
368}
369
Ted Kremenek3abc41f2009-10-15 01:40:34 +0000370
Ted Kremenekf27110f2009-04-23 19:11:35 +0000371// Test stringWithFormat (<rdar://problem/6815234>)
372void test_stringWithFormat() {
373 NSString *string = [[NSString stringWithFormat:@"%ld", (long) 100] retain];
374 [string release];
Ted Kremenek0a1f9c42009-04-23 21:25:57 +0000375 [string release]; // expected-warning{{Incorrect decrement of the reference count}}
Ted Kremenekf27110f2009-04-23 19:11:35 +0000376}
377
Ted Kremenek4b59ccb2009-05-03 06:08:32 +0000378// Test isTrackedObjectType().
Ted Kremenek37467812009-04-23 22:11:07 +0000379typedef NSString* WonkyTypedef;
380@interface TestIsTracked
381+ (WonkyTypedef)newString;
382@end
383
384void test_isTrackedObjectType(void) {
385 NSString *str = [TestIsTracked newString]; // expected-warning{{Potential leak}}
386}
Ted Kremenek49805452009-05-02 01:49:13 +0000387
Ted Kremenek4b59ccb2009-05-03 06:08:32 +0000388// Test isTrackedCFObjectType().
389@interface TestIsCFTracked
390+ (CFStringRef) badNewCFString;
391+ (CFStringRef) newCFString;
392@end
393
394@implementation TestIsCFTracked
395+ (CFStringRef) newCFString {
396 return CFStringCreateWithFormat(kCFAllocatorDefault, ((void*)0), ((CFStringRef) __builtin___CFStringMakeConstantString ("" "%d" "")), 100); // no-warning
397}
398+ (CFStringRef) badNewCFString {
399 return CFStringCreateWithFormat(kCFAllocatorDefault, ((void*)0), ((CFStringRef) __builtin___CFStringMakeConstantString ("" "%d" "")), 100); // expected-warning{{leak}}
400}
401
Ted Kremenek49805452009-05-02 01:49:13 +0000402// Test @synchronized
403void test_synchronized(id x) {
404 @synchronized(x) {
405 NSString *string = [[NSString stringWithFormat:@"%ld", (long) 100] retain]; // expected-warning {{leak}}
406 }
407}
Fariborz Jahanian9290ede2009-11-16 18:57:01 +0000408@end
Zhongxing Xucbbf8552010-01-11 06:52:53 +0000409
410void testOSCompareAndSwapXXBarrier_parameter(NSString **old) {
411 NSString *s = [[NSString alloc] init]; // no-warning
412 if (!COMPARE_SWAP_BARRIER((intptr_t) 0, (intptr_t) s, (intptr_t*) old))
413 [s release];
414 else
415 [*old release];
416}
Zhongxing Xue47550e2010-01-11 07:40:00 +0000417
418void testOSCompareAndSwapXXBarrier_parameter_no_direct_release(NSString **old) {
419 NSString *s = [[NSString alloc] init]; // no-warning
420 if (!COMPARE_SWAP_BARRIER((intptr_t) 0, (intptr_t) s, (intptr_t*) old))
421 [s release];
422 else
423 return;
424}
Anna Zaks00c69a52013-02-02 00:30:04 +0000425
426@interface AlwaysInlineBodyFarmBodies : NSObject {
427 NSString *_value;
428}
429 - (NSString *)_value;
430 - (void)callValue;
431@end
432
433@implementation AlwaysInlineBodyFarmBodies
434
435- (NSString *)_value {
436 if (!_value) {
437 NSString *s = [[NSString alloc] init];
438 if (!OSAtomicCompareAndSwapPtr(0, s, (void**)&_value)) {
439 [s release];
440 }
441 }
442 return _value;
443}
444
445- (void)callValue {
446 [self _value];
447}
Alexander Shaposhnikova1fead22016-09-23 20:49:01 +0000448@end