1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.cocoa.RetainCount,osx.cocoa.Dealloc,debug.ExprInspection -verify -Wno-objc-root-class -analyzer-config eagerly-assume=false %s
2 // RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.cocoa.RetainCount,osx.cocoa.Dealloc,debug.ExprInspection -verify -Wno-objc-root-class -fobjc-arc -analyzer-config eagerly-assume=false %s
4 void clang_analyzer_eval(int);
8 typedef const void * CFTypeRef;
9 extern CFTypeRef CFRetain(CFTypeRef cf);
10 void CFRelease(CFTypeRef cf);
12 typedef signed char BOOL;
13 typedef unsigned int NSUInteger;
14 typedef struct _NSZone NSZone;
15 @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
16 @protocol NSObject - (BOOL)isEqual:(id)object; @end
17 @protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end
18 @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end
19 @protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end
20 @interface NSObject <NSObject> {}
26 -(oneway void)release;
29 @interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>
31 -(id)initWithFormat:(NSString *)f,...;
32 -(BOOL)isEqualToString:(NSString *)s;
35 @interface NSNumber : NSObject {}
37 -(id)initWithInteger:(int)i;
42 @interface Test1 : NSObject {
46 @property (nonatomic, assign) NSString *text;
50 #if !__has_feature(objc_arc)
57 Test1 *cell = [[[Test1 alloc] init] autorelease];
59 NSString *string1 = [[NSString alloc] initWithFormat:@"test %f", 0.0]; // expected-warning {{Potential leak}}
70 @interface MyNumber : NSObject
75 - (id)initWithNumber:(NSNumber *)number;
77 @property (nonatomic, readonly) NSNumber* myNumber;
78 @property (nonatomic, readonly) NSNumber* newMyNumber;
82 @implementation MyNumber
83 @synthesize myNumber=_myNumber;
85 - (id)initWithNumber:(NSNumber *)number
91 _myNumber = [number copy];
97 - (NSNumber*)newMyNumber
100 return [_myNumber retain];
102 return [[NSNumber alloc] initWithInteger:1];
105 - (id)valueForUndefinedKey:(NSString*)key
109 if ([key isEqualToString:@"MyIvarNumberAsPropertyOverReleased"])
110 value = self.myNumber; // _myNumber will be over released, since the value returned from self.myNumber is not retained.
111 else if ([key isEqualToString:@"MyIvarNumberAsPropertyOk"])
112 value = [self.myNumber retain]; // this line fixes the over release
113 else if ([key isEqualToString:@"MyIvarNumberAsNewMyNumber"])
114 value = self.newMyNumber; // this one is ok, since value is returned retained
116 value = [[NSNumber alloc] initWithInteger:0];
118 return [value autorelease]; // expected-warning {{Object autoreleased too many times}}
123 NSNumber* numberFromMyNumberProperty(MyNumber* aMyNumber)
125 NSNumber* result = aMyNumber.myNumber;
127 return [result autorelease]; // expected-warning {{Object autoreleased too many times}}
135 @interface Person : NSObject {
138 @property (retain) NSString * name;
139 @property (assign) id friend;
142 @implementation Person
143 @synthesize name = _name;
146 #if !__has_feature(objc_arc)
147 self.name = [[NSString alloc] init]; // expected-warning {{leak}}
149 [super dealloc]; // expected-warning {{The '_name' ivar in 'Person' was retained by a synthesized property but not released before '[super dealloc]}}
154 #if !__has_feature(objc_arc)
155 void rdar6611873(void) {
156 Person *p = [[[Person alloc] init] autorelease];
158 p.name = [[NSString string] retain]; // expected-warning {{leak}}
159 p.name = [[NSString alloc] init]; // expected-warning {{leak}}
161 p.friend = [[Person alloc] init]; // expected-warning {{leak}}
165 @interface SubPerson : Person
169 @implementation SubPerson
176 #if !__has_feature(objc_arc)
177 // <rdar://problem/9241180> Static analyzer doesn't detect uninitialized variable issues for property accesses
178 @interface RDar9241180
179 @property (readwrite,assign) id x;
180 -(id)testAnalyzer1:(int) y;
181 -(void)testAnalyzer2;
184 @implementation RDar9241180
186 -(id)testAnalyzer1:(int)y {
188 if (y && o.x) // expected-warning {{Property access on an uninitialized object pointer}}
190 return o; // expected-warning {{Undefined or garbage value returned to caller}}
192 -(void)testAnalyzer2 {
194 self.x = y; // expected-warning {{Argument for property setter is an uninitialized value}}
201 // Property accessor synthesis
204 extern void doSomethingWithPerson(Person *p);
205 extern void doSomethingWithName(NSString *name);
207 void testConsistencyRetain(Person *p) {
208 clang_analyzer_eval(p.name == p.name); // expected-warning{{TRUE}}
210 id origName = p.name;
211 clang_analyzer_eval(p.name == origName); // expected-warning{{TRUE}}
212 doSomethingWithPerson(p);
213 clang_analyzer_eval(p.name == origName); // expected-warning{{UNKNOWN}}
216 void testConsistencyAssign(Person *p) {
217 clang_analyzer_eval(p.friend == p.friend); // expected-warning{{TRUE}}
219 id origFriend = p.friend;
220 clang_analyzer_eval(p.friend == origFriend); // expected-warning{{TRUE}}
221 doSomethingWithPerson(p);
222 clang_analyzer_eval(p.friend == origFriend); // expected-warning{{UNKNOWN}}
225 @interface ClassWithShadowedReadWriteProperty {
228 @property (readonly) int someProp;
231 @interface ClassWithShadowedReadWriteProperty ()
232 @property (readwrite) int someProp;
235 @implementation ClassWithShadowedReadWriteProperty
236 - (void)testSynthesisForShadowedReadWriteProperties; {
237 clang_analyzer_eval(self.someProp == self.someProp); // expected-warning{{TRUE}}
241 // Read of shadowed property should not invalidate receiver.
243 clang_analyzer_eval(_f == 1); // expected-warning{{TRUE}}
246 // Call to getter of shadowed property should not invalidate receiver.
247 (void)[self someProp];
248 clang_analyzer_eval(_f == 2); // expected-warning{{TRUE}}
252 // Tests for the analyzer fix that works around a Sema bug
253 // where multiple methods are created for properties in class extensions that
254 // are redeclared in a category method.
255 // The Sema bug is tracked as <rdar://problem/25481164>.
256 @interface ClassWithRedeclaredPropertyInExtensionFollowedByCategory
259 @interface ClassWithRedeclaredPropertyInExtensionFollowedByCategory ()
262 @interface ClassWithRedeclaredPropertyInExtensionFollowedByCategory ()
263 @property (readwrite) int someProp;
264 @property (readonly) int otherProp;
267 @interface ClassWithRedeclaredPropertyInExtensionFollowedByCategory (MyCat)
268 @property (readonly) int someProp;
269 @property (readonly) int otherProp;
272 @implementation ClassWithRedeclaredPropertyInExtensionFollowedByCategory
273 - (void)testSynthesisForRedeclaredProperties; {
274 clang_analyzer_eval(self.someProp == self.someProp); // expected-warning{{TRUE}}
275 clang_analyzer_eval([self someProp] == self.someProp); // expected-warning{{TRUE}}
277 clang_analyzer_eval(self.otherProp == self.otherProp); // expected-warning{{TRUE}}
278 clang_analyzer_eval([self otherProp] == self.otherProp); // expected-warning{{TRUE}}
282 // The relative order of the extension and the category matter, so test both.
283 @interface ClassWithRedeclaredPropertyInCategoryFollowedByExtension
286 @interface ClassWithRedeclaredPropertyInCategoryFollowedByExtension ()
287 @property (readwrite) int someProp;
290 @interface ClassWithRedeclaredPropertyInCategoryFollowedByExtension (MyCat)
291 @property (readonly) int someProp;
294 @implementation ClassWithRedeclaredPropertyInCategoryFollowedByExtension
295 - (void)testSynthesisForRedeclaredProperties; {
296 clang_analyzer_eval(self.someProp == self.someProp); // expected-warning{{TRUE}}
297 clang_analyzer_eval([self someProp] == self.someProp); // expected-warning{{TRUE}}
301 @interface ClassWithSynthesizedPropertyAndGetter
302 @property (readonly) int someProp;
305 @implementation ClassWithSynthesizedPropertyAndGetter
306 @synthesize someProp;
308 // Make sure that the actual getter is inlined and not a getter created
310 - (void)testBodyFarmGetterNotUsed {
311 int i = self.someProp;
312 clang_analyzer_eval(i == 22); // expected-warning {{TRUE}}
320 __attribute__((objc_root_class))
321 @interface ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory
325 @property (nonatomic, readonly) int stuffProperty;
328 @interface ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory (Private)
329 @property (nonatomic, readonly) int stuffProperty;
332 @interface ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory (Internal) <HasStuff>
335 @interface ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory() <HasStuff>
338 @implementation ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory
339 @synthesize stuffProperty = _stuffProperty;
342 (void)self.stuffProperty;
347 // Setter ivar invalidation.
350 @interface ClassWithSetters
351 // Note: These properties have implicit @synthesize implementations to be
352 // backed with ivars.
353 @property (assign) int propWithIvar1;
354 @property (assign) int propWithIvar2;
356 @property (retain) NSNumber *retainedProperty;
360 @interface ClassWithSetters (InOtherTranslationUnit)
361 // The implementation of this property is in another translation unit.
362 // We don't know whether it is backed by an ivar or not.
363 @property (assign) int propInOther;
366 @implementation ClassWithSetters
367 - (void) testSettingPropWithIvarInvalidatesExactlyThatIvar; {
370 self.propWithIvar1 = 66;
372 // Calling the setter of a property backed by the instance variable
373 // should invalidate the storage for the instance variable but not
374 // the rest of the receiver. Ideally we would model the setter completely
375 // but doing so would cause the new value to escape when it is bound
376 // to the ivar. This would cause bad false negatives in the retain count
377 // checker. (There is a test for this scenario in
378 // testWriteRetainedValueToRetainedProperty below).
379 clang_analyzer_eval(_propWithIvar1 == 66); // expected-warning{{UNKNOWN}}
380 clang_analyzer_eval(_propWithIvar2 == 2); // expected-warning{{TRUE}}
383 [self setPropWithIvar1:66];
385 clang_analyzer_eval(_propWithIvar1 == 66); // expected-warning{{UNKNOWN}}
386 clang_analyzer_eval(_propWithIvar2 == 2); // expected-warning{{TRUE}}
389 - (void) testSettingPropWithoutIvarInvalidatesEntireInstance; {
392 self.propInOther = 66;
394 clang_analyzer_eval(_propWithIvar1 == 66); // expected-warning{{UNKNOWN}}
395 clang_analyzer_eval(_propWithIvar2 == 2); // expected-warning{{UNKNOWN}}
399 [self setPropInOther:66];
401 clang_analyzer_eval(_propWithIvar1 == 66); // expected-warning{{UNKNOWN}}
402 clang_analyzer_eval(_propWithIvar2 == 2); // expected-warning{{UNKNOWN}}
405 #if !__has_feature(objc_arc)
406 - (void) testWriteRetainedValueToRetainedProperty; {
407 NSNumber *number = [[NSNumber alloc] initWithInteger:5]; // expected-warning {{Potential leak of an object stored into 'number'}}
409 // Make sure we catch this leak.
410 self.retainedProperty = number;
419 int gBackingForReadWriteClassProp = 0;
421 @interface ClassWithClassProperties
422 @property(class, readonly) int readOnlyClassProp;
424 @property(class) int readWriteClassProp;
426 // Make sure we handle when a class and instance property have the same
427 // name. Test both when instance comes first and when class comes first.
428 @property(readonly) int classAndInstancePropWithSameNameOrderInstanceFirst;
429 @property(class, readonly) int classAndInstancePropWithSameNameOrderInstanceFirst;
431 @property(class, readonly) int classAndInstancePropWithSameNameOrderClassFirst;
432 @property(readonly) int classAndInstancePropWithSameNameOrderClassFirst;
435 @property(class, readonly) int dynamicClassProp;
439 @interface ClassWithClassProperties (OtherTranslationUnit)
440 @property(class, assign) id propInOtherTranslationUnit;
443 @implementation ClassWithClassProperties
445 @dynamic dynamicClassProp;
447 + (int)readOnlyClassProp {
451 + (int)readWriteClassProp {
452 return gBackingForReadWriteClassProp;
455 + (void)setReadWriteClassProp:(int)val {
456 gBackingForReadWriteClassProp = val;
459 - (int)classAndInstancePropWithSameNameOrderInstanceFirst {
463 + (int)classAndInstancePropWithSameNameOrderInstanceFirst {
467 + (int)classAndInstancePropWithSameNameOrderClassFirst {
471 - (int)classAndInstancePropWithSameNameOrderClassFirst {
475 - (void)testInlineClassProp {
476 clang_analyzer_eval(ClassWithClassProperties.readOnlyClassProp == 1); // expected-warning{{TRUE}}
478 ClassWithClassProperties.readWriteClassProp = 7;
479 clang_analyzer_eval(ClassWithClassProperties.readWriteClassProp == 7); // expected-warning{{TRUE}}
480 ClassWithClassProperties.readWriteClassProp = 8;
481 clang_analyzer_eval(ClassWithClassProperties.readWriteClassProp == 8); // expected-warning{{TRUE}}
484 - (void)testUnknownClassProp {
485 clang_analyzer_eval(ClassWithClassProperties.propInOtherTranslationUnit == ClassWithClassProperties.propInOtherTranslationUnit); // expected-warning{{UNKNOWN}}
488 - (void)testEscapeGlobalOnUnknownProp {
489 gBackingForReadWriteClassProp = 33;
490 ClassWithClassProperties.propInOtherTranslationUnit = 0;
491 clang_analyzer_eval(gBackingForReadWriteClassProp == 33); // expected-warning{{UNKNOWN}}
494 - (void)testClassAndInstancePropertyWithSameName {
495 clang_analyzer_eval(self.classAndInstancePropWithSameNameOrderInstanceFirst == 12); // expected-warning{{TRUE}}
496 clang_analyzer_eval(ClassWithClassProperties.classAndInstancePropWithSameNameOrderInstanceFirst == 13); // expected-warning{{TRUE}}
498 clang_analyzer_eval(ClassWithClassProperties.classAndInstancePropWithSameNameOrderClassFirst == 14); // expected-warning{{TRUE}}
499 clang_analyzer_eval(self.classAndInstancePropWithSameNameOrderClassFirst == 15); // expected-warning{{TRUE}}
502 - (void)testDynamicClassProp {
503 clang_analyzer_eval(ClassWithClassProperties.dynamicClassProp == 16); // expected-warning{{UNKNOWN}}
508 @interface SubclassOfClassWithClassProperties : ClassWithClassProperties
511 @implementation SubclassOfClassWithClassProperties
512 + (int)dynamicClassProp; {
516 - (void)testDynamicClassProp {
517 clang_analyzer_eval(SubclassOfClassWithClassProperties.dynamicClassProp == 16); // expected-warning{{TRUE}}
523 #if !__has_feature(objc_arc)
524 void testOverrelease(Person *p, int coin) {
527 [p.name release]; // expected-warning{{not owned}}
530 [p.friend release]; // expected-warning{{not owned}}
533 id friend = p.friend;
534 doSomethingWithPerson(p);
535 [friend release]; // expected-warning{{not owned}}
540 // <rdar://problem/16333368>
541 @implementation Person (Rdar16333368)
543 - (void)testDeliberateRelease:(Person *)other {
544 doSomethingWithName(self.name);
545 [_name release]; // no-warning
548 doSomethingWithName(other->_name);
549 [other.name release]; // no-warning
552 - (void)deliberateReleaseFalseNegative {
553 // This is arguably a false negative because the result of p.friend shouldn't
554 // be released, even though we are manipulating the ivar in between the two
561 - (void)testRetainAndRelease {
564 [self.name release]; // expected-warning{{not owned}}
567 - (void)testRetainAndReleaseIVar {
576 @interface IntWrapper
580 @implementation IntWrapper
584 void testConsistencyInt(IntWrapper *w) {
585 clang_analyzer_eval(w.value == w.value); // expected-warning{{TRUE}}
587 int origValue = w.value;
591 clang_analyzer_eval(w.value == 42); // expected-warning{{TRUE}}
594 void testConsistencyInt2(IntWrapper *w) {
598 clang_analyzer_eval(w.value == 42); // expected-warning{{TRUE}}
602 @interface IntWrapperAuto
606 @implementation IntWrapperAuto
609 void testConsistencyIntAuto(IntWrapperAuto *w) {
610 clang_analyzer_eval(w.value == w.value); // expected-warning{{TRUE}}
612 int origValue = w.value;
616 clang_analyzer_eval(w.value == 42); // expected-warning{{TRUE}}
619 void testConsistencyIntAuto2(IntWrapperAuto *w) {
623 clang_analyzer_eval(w.value == 42); // expected-warning{{TRUE}}
631 @interface StructWrapper
632 @property IntWrapperStruct inner;
635 @implementation StructWrapper
639 void testConsistencyStruct(StructWrapper *w) {
640 clang_analyzer_eval(w.inner.value == w.inner.value); // expected-warning{{TRUE}}
642 int origValue = w.inner.value;
646 clang_analyzer_eval(w.inner.value == 42); // expected-warning{{TRUE}}
650 @interface OpaqueIntWrapper
654 // For now, don't assume a property is implemented using an ivar unless we can
655 // actually see that it is.
656 void testOpaqueConsistency(OpaqueIntWrapper *w) {
657 clang_analyzer_eval(w.value == w.value); // expected-warning{{UNKNOWN}}
661 #if !__has_feature(objc_arc)
662 // Test quite a few cases of retain/release issues.
664 @interface RetainCountTesting
665 @property (strong) id ownedProp;
666 @property (unsafe_unretained) id unownedProp;
667 @property (nonatomic, strong) id manualProp;
668 @property (readonly) id readonlyProp;
669 @property (nonatomic, readwrite/*, assign */) id implicitManualProp; // expected-warning {{'assign' is assumed}} expected-warning {{'assign' not appropriate}}
670 @property (nonatomic, readwrite/*, assign */) id implicitSynthProp; // expected-warning {{'assign' is assumed}} expected-warning {{'assign' not appropriate}}
671 @property CFTypeRef cfProp;
674 @implementation RetainCountTesting {
682 - (void)setImplicitManualProp:(id)newValue {}
684 - (void)testOverreleaseOwnedIvar {
686 [_ownedProp release];
687 [_ownedProp release];
688 [_ownedProp release]; // FIXME-warning{{used after it is released}}
691 - (void)testOverreleaseUnownedIvar {
692 [_unownedProp retain];
693 [_unownedProp release];
694 [_unownedProp release]; // FIXME-warning{{not owned at this point by the caller}}
697 - (void)testOverreleaseIvarOnly {
701 [_ivarOnly release]; // FIXME-warning{{used after it is released}}
704 - (void)testOverreleaseReadonlyIvar {
705 [_readonlyProp retain];
706 [_readonlyProp release];
707 [_readonlyProp release];
708 [_readonlyProp release]; // FIXME-warning{{used after it is released}}
711 - (void)testOverreleaseImplicitManualIvar {
712 [_implicitManualProp retain];
713 [_implicitManualProp release];
714 [_implicitManualProp release];
715 [_implicitManualProp release]; // FIXME-warning{{used after it is released}}
718 - (void)testOverreleaseImplicitSynthIvar {
719 [_implicitSynthProp retain];
720 [_implicitSynthProp release];
721 [_implicitSynthProp release]; // FIXME-warning{{not owned at this point by the caller}}
724 - (void)testOverreleaseCF {
728 CFRelease(_cfProp); // FIXME-warning{{used after it is released}}
731 - (void)testOverreleaseOwnedIvarUse {
733 [_ownedProp release];
734 [_ownedProp release];
735 [_ownedProp myMethod]; // FIXME-warning{{used after it is released}}
738 - (void)testOverreleaseIvarOnlyUse {
742 [_ivarOnly myMethod]; // FIXME-warning{{used after it is released}}
745 - (void)testOverreleaseCFUse {
750 extern void CFUse(CFTypeRef);
751 CFUse(_cfProp); // FIXME-warning{{used after it is released}}
754 - (void)testOverreleaseOwnedIvarAutoreleaseOkay {
756 [_ownedProp release];
757 [_ownedProp autorelease];
760 - (void)testOverreleaseIvarOnlyAutoreleaseOkay {
763 [_ivarOnly autorelease];
766 - (void)testOverreleaseOwnedIvarAutorelease {
768 [_ownedProp release];
769 [_ownedProp autorelease];
770 [_ownedProp autorelease];
771 } // FIXME-warning{{Object autoreleased too many times}}
773 - (void)testOverreleaseIvarOnlyAutorelease {
776 [_ivarOnly autorelease];
777 [_ivarOnly autorelease];
778 } // FIXME-warning{{Object autoreleased too many times}}
780 - (void)testPropertyAccessThenReleaseOwned {
781 id owned = [self.ownedProp retain];
783 [_ownedProp release];
784 clang_analyzer_eval(owned == _ownedProp); // expected-warning{{TRUE}}
787 - (void)testPropertyAccessThenReleaseOwned2 {
788 id fromIvar = _ownedProp;
789 id owned = [self.ownedProp retain];
792 clang_analyzer_eval(owned == fromIvar); // expected-warning{{TRUE}}
795 - (void)testPropertyAccessThenReleaseUnowned {
796 id unowned = [self.unownedProp retain];
798 [_unownedProp release]; // FIXME-warning{{not owned}}
801 - (void)testPropertyAccessThenReleaseUnowned2 {
802 id fromIvar = _unownedProp;
803 id unowned = [self.unownedProp retain];
805 clang_analyzer_eval(unowned == fromIvar); // expected-warning{{TRUE}}
806 [fromIvar release]; // FIXME-warning{{not owned}}
809 - (void)testPropertyAccessThenReleaseManual {
810 id prop = [self.manualProp retain];
812 [_manualProp release]; // no-warning
815 - (void)testPropertyAccessThenReleaseManual2 {
816 id fromIvar = _manualProp;
817 id prop = [self.manualProp retain];
819 clang_analyzer_eval(prop == fromIvar); // expected-warning{{TRUE}}
820 [fromIvar release]; // no-warning
823 - (void)testPropertyAccessThenReleaseCF {
824 CFTypeRef owned = CFRetain(self.cfProp);
826 CFRelease(_cfProp); // no-warning
827 clang_analyzer_eval(owned == _cfProp); // expected-warning{{TRUE}}
830 - (void)testPropertyAccessThenReleaseCF2 {
831 CFTypeRef fromIvar = _cfProp;
832 CFTypeRef owned = CFRetain(self.cfProp);
835 clang_analyzer_eval(owned == fromIvar); // expected-warning{{TRUE}}
838 - (void)testPropertyAccessThenReleaseReadonly {
839 id prop = [self.readonlyProp retain];
841 [_readonlyProp release]; // no-warning
844 - (void)testPropertyAccessThenReleaseReadonly2 {
845 id fromIvar = _readonlyProp;
846 id prop = [self.readonlyProp retain];
848 clang_analyzer_eval(prop == fromIvar); // expected-warning{{TRUE}}
849 [fromIvar release]; // no-warning
852 - (void)testPropertyAccessThenReleaseImplicitManual {
853 id prop = [self.implicitManualProp retain];
855 [_implicitManualProp release]; // no-warning
858 - (void)testPropertyAccessThenReleaseImplicitManual2 {
859 id fromIvar = _implicitManualProp;
860 id prop = [self.implicitManualProp retain];
862 clang_analyzer_eval(prop == fromIvar); // expected-warning{{TRUE}}
863 [fromIvar release]; // no-warning
866 - (void)testPropertyAccessThenReleaseImplicitSynth {
867 id prop = [self.implicitSynthProp retain];
869 [_implicitSynthProp release]; // FIXME-warning{{not owned}}
872 - (void)testPropertyAccessThenReleaseImplicitSynth2 {
873 id fromIvar = _implicitSynthProp;
874 id prop = [self.implicitSynthProp retain];
876 clang_analyzer_eval(prop == fromIvar); // expected-warning{{TRUE}}
877 [fromIvar release]; // FIXME-warning{{not owned}}
880 - (id)getUnownedFromProperty {
882 [_ownedProp autorelease];
883 return _ownedProp; // no-warning
886 - (id)transferUnownedFromProperty {
888 [_ownedProp autorelease];
889 return [_ownedProp autorelease]; // no-warning
892 - (id)transferOwnedFromProperty __attribute__((ns_returns_retained)) {
894 [_ownedProp autorelease];
895 return _ownedProp; // no-warning
898 - (void)testAssignOwned:(id)newValue {
899 _ownedProp = newValue;
900 [_ownedProp release]; // FIXME: no-warning{{not owned}}
903 - (void)testAssignUnowned:(id)newValue {
904 _unownedProp = newValue;
905 [_unownedProp release]; // FIXME: no-warning{{not owned}}
908 - (void)testAssignIvarOnly:(id)newValue {
909 _ivarOnly = newValue;
910 [_ivarOnly release]; // FIXME: no-warning{{not owned}}
913 - (void)testAssignCF:(CFTypeRef)newValue {
915 CFRelease(_cfProp); // FIXME: no-warning{{not owned}}
918 - (void)testAssignReadonly:(id)newValue {
919 _readonlyProp = newValue;
920 [_readonlyProp release]; // FIXME: no-warning{{not owned}}
923 - (void)testAssignImplicitManual:(id)newValue {
924 _implicitManualProp = newValue;
925 [_implicitManualProp release]; // FIXME: no-warning{{not owned}}
928 - (void)testAssignImplicitSynth:(id)newValue {
929 _implicitSynthProp = newValue;
930 [_implicitSynthProp release]; // FIXME: no-warning{{not owned}}
933 - (void)testAssignOwnedOkay:(id)newValue {
934 _ownedProp = [newValue retain];
935 [_ownedProp release]; // no-warning
938 - (void)testAssignUnownedOkay:(id)newValue {
939 _unownedProp = [newValue retain];
940 [_unownedProp release]; // no-warning
943 - (void)testAssignIvarOnlyOkay:(id)newValue {
944 _ivarOnly = [newValue retain];
945 [_ivarOnly release]; // no-warning
948 - (void)testAssignCFOkay:(CFTypeRef)newValue {
949 _cfProp = CFRetain(newValue);
950 CFRelease(_cfProp); // no-warning
953 - (void)testAssignReadonlyOkay:(id)newValue {
954 _readonlyProp = [newValue retain];
955 [_readonlyProp release]; // FIXME: no-warning{{not owned}}
958 - (void)testAssignImplicitManualOkay:(id)newValue {
959 _implicitManualProp = [newValue retain];
960 [_implicitManualProp release]; // FIXME: no-warning{{not owned}}
963 - (void)testAssignImplicitSynthOkay:(id)newValue {
964 _implicitSynthProp = [newValue retain];
965 [_implicitSynthProp release]; // FIXME: no-warning{{not owned}}
968 // rdar://problem/19862648
969 - (void)establishIvarIsNilDuringLoops {
970 extern id getRandomObject(void);
972 int i = 4; // Must be at least 4 to trigger the bug.
975 if (getRandomObject())
978 x = getRandomObject();
983 // rdar://problem/20335433
984 - (void)retainIvarAndInvalidateSelf {
985 extern void invalidate(id);
986 [_unownedProp retain];
988 [_unownedProp release]; // no-warning
994 @property(nonatomic, readonly) int value;
997 @implementation Wrapper
1001 void testNoCrashWhenAccessPropertyAndThereAreNoDirectBindingsAtAll(void) {
1010 @interface ExplicitAccessorInCategory : NSObject
1011 @property(readonly) int normal;
1013 @property(readonly) int no_custom_accessor;
1016 @interface ExplicitAccessorInCategory ()
1017 @property(readonly) int in_category;
1019 @property(readonly) int still_no_custom_accessor;
1020 // This is an ordinary method, not a getter.
1021 - (int)still_no_custom_accessor;
1024 @interface ExplicitAccessorInCategory ()
1027 // This is an ordinary method, not a getter.
1028 - (int)no_custom_accessor;
1031 @implementation ExplicitAccessorInCategory
1033 // Make sure we don't farm bodies for explicit accessors: in particular,
1034 // we're not sure that the accessor always returns the same value.
1035 clang_analyzer_eval(self.normal == self.normal); // expected-warning{{UNKNOWN}}
1036 // Also this used to crash.
1037 clang_analyzer_eval(self.in_category == self.in_category); // expected-warning{{UNKNOWN}}
1039 // When there is no explicit accessor defined (even if it looks like there is),
1040 // farm the getter body and see if it does actually always yield the same value.
1041 clang_analyzer_eval(self.no_custom_accessor == self.no_custom_accessor); // expected-warning{{TRUE}}
1042 clang_analyzer_eval(self.still_no_custom_accessor == self.still_no_custom_accessor); // expected-warning{{TRUE}}
1047 @property (assign) NSObject *o;
1048 - (NSObject *)getShadowedIvar;
1049 - (void)clearShadowedIvar;
1050 - (NSObject *)getShadowedProp;
1051 - (void)clearShadowedProp;
1053 @property (assign) NSObject *o2;
1056 @implementation Shadowed
1057 - (NSObject *)getShadowedIvar {
1060 - (void)clearShadowedIvar {
1063 - (NSObject *)getShadowedProp {
1066 - (void)clearShadowedProp {
1071 @interface Shadowing : Shadowed
1074 @implementation Shadowing
1075 // Property 'o' is declared in the superclass but synthesized here.
1076 // This creates a separate ivar that shadows the superclass's ivar,
1077 // but the old ivar is still accessible from the methods of the superclass.
1078 // The old property, however, is not accessible with the property syntax
1079 // even from the superclass methods.
1082 -(void)testPropertyShadowing {
1083 NSObject *oo = self.o; // no-crash
1084 clang_analyzer_eval(self.o == oo); // expected-warning{{TRUE}}
1085 clang_analyzer_eval([self getShadowedIvar] == oo); // expected-warning{{UNKNOWN}}
1086 [self clearShadowedIvar];
1087 clang_analyzer_eval(self.o == oo); // expected-warning{{TRUE}}
1088 clang_analyzer_eval([self getShadowedIvar] == oo); // expected-warning{{UNKNOWN}}
1089 clang_analyzer_eval([self getShadowedIvar] == nil); // expected-warning{{TRUE}}
1092 @synthesize o2 = ooo2;
1094 -(void)testPropertyShadowingWithExplicitIvar {
1095 NSObject *oo2 = self.o2; // no-crash