1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.cocoa.RetainCount,osx.cocoa.Dealloc,debug.ExprInspection -analyzer-store=region -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 -analyzer-store=region -verify -Wno-objc-root-class -fobjc-arc -analyzer-config eagerly-assume=false %s
4 void clang_analyzer_eval(int);
6 typedef const void * CFTypeRef;
7 extern CFTypeRef CFRetain(CFTypeRef cf);
8 void CFRelease(CFTypeRef cf);
10 typedef signed char BOOL;
11 typedef unsigned int NSUInteger;
12 typedef struct _NSZone NSZone;
13 @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
14 @protocol NSObject - (BOOL)isEqual:(id)object; @end
15 @protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end
16 @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end
17 @protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end
18 @interface NSObject <NSObject> {}
24 -(oneway void)release;
27 @interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>
29 -(id)initWithFormat:(NSString *)f,...;
30 -(BOOL)isEqualToString:(NSString *)s;
33 @interface NSNumber : NSObject {}
35 -(id)initWithInteger:(int)i;
40 @interface Test1 : NSObject {
44 @property (nonatomic, assign) NSString *text;
48 #if !__has_feature(objc_arc)
55 Test1 *cell = [[[Test1 alloc] init] autorelease];
57 NSString *string1 = [[NSString alloc] initWithFormat:@"test %f", 0.0]; // expected-warning {{Potential leak}}
68 @interface MyNumber : NSObject
73 - (id)initWithNumber:(NSNumber *)number;
75 @property (nonatomic, readonly) NSNumber* myNumber;
76 @property (nonatomic, readonly) NSNumber* newMyNumber;
80 @implementation MyNumber
81 @synthesize myNumber=_myNumber;
83 - (id)initWithNumber:(NSNumber *)number
89 _myNumber = [number copy];
95 - (NSNumber*)newMyNumber
98 return [_myNumber retain];
100 return [[NSNumber alloc] initWithInteger:1];
103 - (id)valueForUndefinedKey:(NSString*)key
107 if ([key isEqualToString:@"MyIvarNumberAsPropertyOverReleased"])
108 value = self.myNumber; // _myNumber will be over released, since the value returned from self.myNumber is not retained.
109 else if ([key isEqualToString:@"MyIvarNumberAsPropertyOk"])
110 value = [self.myNumber retain]; // this line fixes the over release
111 else if ([key isEqualToString:@"MyIvarNumberAsNewMyNumber"])
112 value = self.newMyNumber; // this one is ok, since value is returned retained
114 value = [[NSNumber alloc] initWithInteger:0];
116 return [value autorelease]; // expected-warning {{Object autoreleased too many times}}
121 NSNumber* numberFromMyNumberProperty(MyNumber* aMyNumber)
123 NSNumber* result = aMyNumber.myNumber;
125 return [result autorelease]; // expected-warning {{Object autoreleased too many times}}
133 @interface Person : NSObject {
136 @property (retain) NSString * name;
137 @property (assign) id friend;
140 @implementation Person
141 @synthesize name = _name;
144 #if !__has_feature(objc_arc)
145 self.name = [[NSString alloc] init]; // expected-warning {{leak}}
147 [super dealloc]; // expected-warning {{The '_name' ivar in 'Person' was retained by a synthesized property but not released before '[super dealloc]}}
152 #if !__has_feature(objc_arc)
154 Person *p = [[[Person alloc] init] autorelease];
156 p.name = [[NSString string] retain]; // expected-warning {{leak}}
157 p.name = [[NSString alloc] init]; // expected-warning {{leak}}
159 p.friend = [[Person alloc] init]; // expected-warning {{leak}}
163 @interface SubPerson : Person
167 @implementation SubPerson
174 #if !__has_feature(objc_arc)
175 // <rdar://problem/9241180> Static analyzer doesn't detect uninitialized variable issues for property accesses
176 @interface RDar9241180
177 @property (readwrite,assign) id x;
178 -(id)testAnalyzer1:(int) y;
179 -(void)testAnalyzer2;
182 @implementation RDar9241180
184 -(id)testAnalyzer1:(int)y {
186 if (y && o.x) // expected-warning {{Property access on an uninitialized object pointer}}
188 return o; // expected-warning {{Undefined or garbage value returned to caller}}
190 -(void)testAnalyzer2 {
192 self.x = y; // expected-warning {{Argument for property setter is an uninitialized value}}
199 // Property accessor synthesis
202 extern void doSomethingWithPerson(Person *p);
203 extern void doSomethingWithName(NSString *name);
205 void testConsistencyRetain(Person *p) {
206 clang_analyzer_eval(p.name == p.name); // expected-warning{{TRUE}}
208 id origName = p.name;
209 clang_analyzer_eval(p.name == origName); // expected-warning{{TRUE}}
210 doSomethingWithPerson(p);
211 clang_analyzer_eval(p.name == origName); // expected-warning{{UNKNOWN}}
214 void testConsistencyAssign(Person *p) {
215 clang_analyzer_eval(p.friend == p.friend); // expected-warning{{TRUE}}
217 id origFriend = p.friend;
218 clang_analyzer_eval(p.friend == origFriend); // expected-warning{{TRUE}}
219 doSomethingWithPerson(p);
220 clang_analyzer_eval(p.friend == origFriend); // expected-warning{{UNKNOWN}}
223 @interface ClassWithShadowedReadWriteProperty {
226 @property (readonly) int someProp;
229 @interface ClassWithShadowedReadWriteProperty ()
230 @property (readwrite) int someProp;
233 @implementation ClassWithShadowedReadWriteProperty
234 - (void)testSynthesisForShadowedReadWriteProperties; {
235 clang_analyzer_eval(self.someProp == self.someProp); // expected-warning{{TRUE}}
239 // Read of shadowed property should not invalidate receiver.
241 clang_analyzer_eval(_f == 1); // expected-warning{{TRUE}}
244 // Call to getter of shadowed property should not invalidate receiver.
245 (void)[self someProp];
246 clang_analyzer_eval(_f == 2); // expected-warning{{TRUE}}
250 // Tests for the analyzer fix that works around a Sema bug
251 // where multiple methods are created for properties in class extensions that
252 // are redeclared in a category method.
253 // The Sema bug is tracked as <rdar://problem/25481164>.
254 @interface ClassWithRedeclaredPropertyInExtensionFollowedByCategory
257 @interface ClassWithRedeclaredPropertyInExtensionFollowedByCategory ()
260 @interface ClassWithRedeclaredPropertyInExtensionFollowedByCategory ()
261 @property (readwrite) int someProp;
262 @property (readonly) int otherProp;
265 @interface ClassWithRedeclaredPropertyInExtensionFollowedByCategory (MyCat)
266 @property (readonly) int someProp;
267 @property (readonly) int otherProp;
270 @implementation ClassWithRedeclaredPropertyInExtensionFollowedByCategory
271 - (void)testSynthesisForRedeclaredProperties; {
272 clang_analyzer_eval(self.someProp == self.someProp); // expected-warning{{TRUE}}
273 clang_analyzer_eval([self someProp] == self.someProp); // expected-warning{{TRUE}}
275 clang_analyzer_eval(self.otherProp == self.otherProp); // expected-warning{{TRUE}}
276 clang_analyzer_eval([self otherProp] == self.otherProp); // expected-warning{{TRUE}}
280 // The relative order of the extension and the category matter, so test both.
281 @interface ClassWithRedeclaredPropertyInCategoryFollowedByExtension
284 @interface ClassWithRedeclaredPropertyInCategoryFollowedByExtension ()
285 @property (readwrite) int someProp;
288 @interface ClassWithRedeclaredPropertyInCategoryFollowedByExtension (MyCat)
289 @property (readonly) int someProp;
292 @implementation ClassWithRedeclaredPropertyInCategoryFollowedByExtension
293 - (void)testSynthesisForRedeclaredProperties; {
294 clang_analyzer_eval(self.someProp == self.someProp); // expected-warning{{TRUE}}
295 clang_analyzer_eval([self someProp] == self.someProp); // expected-warning{{TRUE}}
299 @interface ClassWithSynthesizedPropertyAndGetter
300 @property (readonly) int someProp;
303 @implementation ClassWithSynthesizedPropertyAndGetter
304 @synthesize someProp;
306 // Make sure that the actual getter is inlined and not a getter created
308 - (void)testBodyFarmGetterNotUsed {
309 int i = self.someProp;
310 clang_analyzer_eval(i == 22); // expected-warning {{TRUE}}
318 __attribute__((objc_root_class))
319 @interface ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory
323 @property (nonatomic, readonly) int stuffProperty;
326 @interface ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory (Private)
327 @property (nonatomic, readonly) int stuffProperty;
330 @interface ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory (Internal) <HasStuff>
333 @interface ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory() <HasStuff>
336 @implementation ClassWithPrivatePropertyInClassExtensionWithProtocolShadowingCategory
337 @synthesize stuffProperty = _stuffProperty;
340 (void)self.stuffProperty;
345 // Setter ivar invalidation.
348 @interface ClassWithSetters
349 // Note: These properties have implicit @synthesize implementations to be
350 // backed with ivars.
351 @property (assign) int propWithIvar1;
352 @property (assign) int propWithIvar2;
354 @property (retain) NSNumber *retainedProperty;
358 @interface ClassWithSetters (InOtherTranslationUnit)
359 // The implementation of this property is in another translation unit.
360 // We don't know whether it is backed by an ivar or not.
361 @property (assign) int propInOther;
364 @implementation ClassWithSetters
365 - (void) testSettingPropWithIvarInvalidatesExactlyThatIvar; {
368 self.propWithIvar1 = 66;
370 // Calling the setter of a property backed by the instance variable
371 // should invalidate the storage for the instance variable but not
372 // the rest of the receiver. Ideally we would model the setter completely
373 // but doing so would cause the new value to escape when it is bound
374 // to the ivar. This would cause bad false negatives in the retain count
375 // checker. (There is a test for this scenario in
376 // testWriteRetainedValueToRetainedProperty below).
377 clang_analyzer_eval(_propWithIvar1 == 66); // expected-warning{{UNKNOWN}}
378 clang_analyzer_eval(_propWithIvar2 == 2); // expected-warning{{TRUE}}
381 [self setPropWithIvar1:66];
383 clang_analyzer_eval(_propWithIvar1 == 66); // expected-warning{{UNKNOWN}}
384 clang_analyzer_eval(_propWithIvar2 == 2); // expected-warning{{TRUE}}
387 - (void) testSettingPropWithoutIvarInvalidatesEntireInstance; {
390 self.propInOther = 66;
392 clang_analyzer_eval(_propWithIvar1 == 66); // expected-warning{{UNKNOWN}}
393 clang_analyzer_eval(_propWithIvar2 == 2); // expected-warning{{UNKNOWN}}
397 [self setPropInOther:66];
399 clang_analyzer_eval(_propWithIvar1 == 66); // expected-warning{{UNKNOWN}}
400 clang_analyzer_eval(_propWithIvar2 == 2); // expected-warning{{UNKNOWN}}
403 #if !__has_feature(objc_arc)
404 - (void) testWriteRetainedValueToRetainedProperty; {
405 NSNumber *number = [[NSNumber alloc] initWithInteger:5]; // expected-warning {{Potential leak of an object stored into 'number'}}
407 // Make sure we catch this leak.
408 self.retainedProperty = number;
417 int gBackingForReadWriteClassProp = 0;
419 @interface ClassWithClassProperties
420 @property(class, readonly) int readOnlyClassProp;
422 @property(class) int readWriteClassProp;
424 // Make sure we handle when a class and instance property have the same
425 // name. Test both when instance comes first and when class comes first.
426 @property(readonly) int classAndInstancePropWithSameNameOrderInstanceFirst;
427 @property(class, readonly) int classAndInstancePropWithSameNameOrderInstanceFirst;
429 @property(class, readonly) int classAndInstancePropWithSameNameOrderClassFirst;
430 @property(readonly) int classAndInstancePropWithSameNameOrderClassFirst;
433 @property(class, readonly) int dynamicClassProp;
437 @interface ClassWithClassProperties (OtherTranslationUnit)
438 @property(class, assign) id propInOtherTranslationUnit;
441 @implementation ClassWithClassProperties
443 @dynamic dynamicClassProp;
445 + (int)readOnlyClassProp {
449 + (int)readWriteClassProp {
450 return gBackingForReadWriteClassProp;
453 + (void)setReadWriteClassProp:(int)val {
454 gBackingForReadWriteClassProp = val;
457 - (int)classAndInstancePropWithSameNameOrderInstanceFirst {
461 + (int)classAndInstancePropWithSameNameOrderInstanceFirst {
465 + (int)classAndInstancePropWithSameNameOrderClassFirst {
469 - (int)classAndInstancePropWithSameNameOrderClassFirst {
473 - (void)testInlineClassProp {
474 clang_analyzer_eval(ClassWithClassProperties.readOnlyClassProp == 1); // expected-warning{{TRUE}}
476 ClassWithClassProperties.readWriteClassProp = 7;
477 clang_analyzer_eval(ClassWithClassProperties.readWriteClassProp == 7); // expected-warning{{TRUE}}
478 ClassWithClassProperties.readWriteClassProp = 8;
479 clang_analyzer_eval(ClassWithClassProperties.readWriteClassProp == 8); // expected-warning{{TRUE}}
482 - (void)testUnknownClassProp {
483 clang_analyzer_eval(ClassWithClassProperties.propInOtherTranslationUnit == ClassWithClassProperties.propInOtherTranslationUnit); // expected-warning{{UNKNOWN}}
486 - (void)testEscapeGlobalOnUnknownProp {
487 gBackingForReadWriteClassProp = 33;
488 ClassWithClassProperties.propInOtherTranslationUnit = 0;
489 clang_analyzer_eval(gBackingForReadWriteClassProp == 33); // expected-warning{{UNKNOWN}}
492 - (void)testClassAndInstancePropertyWithSameName {
493 clang_analyzer_eval(self.classAndInstancePropWithSameNameOrderInstanceFirst == 12); // expected-warning{{TRUE}}
494 clang_analyzer_eval(ClassWithClassProperties.classAndInstancePropWithSameNameOrderInstanceFirst == 13); // expected-warning{{TRUE}}
496 clang_analyzer_eval(ClassWithClassProperties.classAndInstancePropWithSameNameOrderClassFirst == 14); // expected-warning{{TRUE}}
497 clang_analyzer_eval(self.classAndInstancePropWithSameNameOrderClassFirst == 15); // expected-warning{{TRUE}}
500 - (void)testDynamicClassProp {
501 clang_analyzer_eval(ClassWithClassProperties.dynamicClassProp == 16); // expected-warning{{UNKNOWN}}
506 @interface SubclassOfClassWithClassProperties : ClassWithClassProperties
509 @implementation SubclassOfClassWithClassProperties
510 + (int)dynamicClassProp; {
514 - (void)testDynamicClassProp {
515 clang_analyzer_eval(SubclassOfClassWithClassProperties.dynamicClassProp == 16); // expected-warning{{TRUE}}
521 #if !__has_feature(objc_arc)
522 void testOverrelease(Person *p, int coin) {
525 [p.name release]; // expected-warning{{not owned}}
528 [p.friend release]; // expected-warning{{not owned}}
531 id friend = p.friend;
532 doSomethingWithPerson(p);
533 [friend release]; // expected-warning{{not owned}}
538 // <rdar://problem/16333368>
539 @implementation Person (Rdar16333368)
541 - (void)testDeliberateRelease:(Person *)other {
542 doSomethingWithName(self.name);
543 [_name release]; // no-warning
546 doSomethingWithName(other->_name);
547 [other.name release]; // no-warning
550 - (void)deliberateReleaseFalseNegative {
551 // This is arguably a false negative because the result of p.friend shouldn't
552 // be released, even though we are manipulating the ivar in between the two
559 - (void)testRetainAndRelease {
562 [self.name release]; // expected-warning{{not owned}}
565 - (void)testRetainAndReleaseIVar {
574 @interface IntWrapper
578 @implementation IntWrapper
582 void testConsistencyInt(IntWrapper *w) {
583 clang_analyzer_eval(w.value == w.value); // expected-warning{{TRUE}}
585 int origValue = w.value;
589 clang_analyzer_eval(w.value == 42); // expected-warning{{TRUE}}
592 void testConsistencyInt2(IntWrapper *w) {
596 clang_analyzer_eval(w.value == 42); // expected-warning{{TRUE}}
600 @interface IntWrapperAuto
604 @implementation IntWrapperAuto
607 void testConsistencyIntAuto(IntWrapperAuto *w) {
608 clang_analyzer_eval(w.value == w.value); // expected-warning{{TRUE}}
610 int origValue = w.value;
614 clang_analyzer_eval(w.value == 42); // expected-warning{{TRUE}}
617 void testConsistencyIntAuto2(IntWrapperAuto *w) {
621 clang_analyzer_eval(w.value == 42); // expected-warning{{TRUE}}
629 @interface StructWrapper
630 @property IntWrapperStruct inner;
633 @implementation StructWrapper
637 void testConsistencyStruct(StructWrapper *w) {
638 clang_analyzer_eval(w.inner.value == w.inner.value); // expected-warning{{TRUE}}
640 int origValue = w.inner.value;
644 clang_analyzer_eval(w.inner.value == 42); // expected-warning{{TRUE}}
648 @interface OpaqueIntWrapper
652 // For now, don't assume a property is implemented using an ivar unless we can
653 // actually see that it is.
654 void testOpaqueConsistency(OpaqueIntWrapper *w) {
655 clang_analyzer_eval(w.value == w.value); // expected-warning{{UNKNOWN}}
659 #if !__has_feature(objc_arc)
660 // Test quite a few cases of retain/release issues.
662 @interface RetainCountTesting
663 @property (strong) id ownedProp;
664 @property (unsafe_unretained) id unownedProp;
665 @property (nonatomic, strong) id manualProp;
666 @property (readonly) id readonlyProp;
667 @property (nonatomic, readwrite/*, assign */) id implicitManualProp; // expected-warning {{'assign' is assumed}} expected-warning {{'assign' not appropriate}}
668 @property (nonatomic, readwrite/*, assign */) id implicitSynthProp; // expected-warning {{'assign' is assumed}} expected-warning {{'assign' not appropriate}}
669 @property CFTypeRef cfProp;
672 @implementation RetainCountTesting {
680 - (void)setImplicitManualProp:(id)newValue {}
682 - (void)testOverreleaseOwnedIvar {
684 [_ownedProp release];
685 [_ownedProp release];
686 [_ownedProp release]; // FIXME-warning{{used after it is released}}
689 - (void)testOverreleaseUnownedIvar {
690 [_unownedProp retain];
691 [_unownedProp release];
692 [_unownedProp release]; // FIXME-warning{{not owned at this point by the caller}}
695 - (void)testOverreleaseIvarOnly {
699 [_ivarOnly release]; // FIXME-warning{{used after it is released}}
702 - (void)testOverreleaseReadonlyIvar {
703 [_readonlyProp retain];
704 [_readonlyProp release];
705 [_readonlyProp release];
706 [_readonlyProp release]; // FIXME-warning{{used after it is released}}
709 - (void)testOverreleaseImplicitManualIvar {
710 [_implicitManualProp retain];
711 [_implicitManualProp release];
712 [_implicitManualProp release];
713 [_implicitManualProp release]; // FIXME-warning{{used after it is released}}
716 - (void)testOverreleaseImplicitSynthIvar {
717 [_implicitSynthProp retain];
718 [_implicitSynthProp release];
719 [_implicitSynthProp release]; // FIXME-warning{{not owned at this point by the caller}}
722 - (void)testOverreleaseCF {
726 CFRelease(_cfProp); // FIXME-warning{{used after it is released}}
729 - (void)testOverreleaseOwnedIvarUse {
731 [_ownedProp release];
732 [_ownedProp release];
733 [_ownedProp myMethod]; // FIXME-warning{{used after it is released}}
736 - (void)testOverreleaseIvarOnlyUse {
740 [_ivarOnly myMethod]; // FIXME-warning{{used after it is released}}
743 - (void)testOverreleaseCFUse {
748 extern void CFUse(CFTypeRef);
749 CFUse(_cfProp); // FIXME-warning{{used after it is released}}
752 - (void)testOverreleaseOwnedIvarAutoreleaseOkay {
754 [_ownedProp release];
755 [_ownedProp autorelease];
758 - (void)testOverreleaseIvarOnlyAutoreleaseOkay {
761 [_ivarOnly autorelease];
764 - (void)testOverreleaseOwnedIvarAutorelease {
766 [_ownedProp release];
767 [_ownedProp autorelease];
768 [_ownedProp autorelease];
769 } // FIXME-warning{{Object autoreleased too many times}}
771 - (void)testOverreleaseIvarOnlyAutorelease {
774 [_ivarOnly autorelease];
775 [_ivarOnly autorelease];
776 } // FIXME-warning{{Object autoreleased too many times}}
778 - (void)testPropertyAccessThenReleaseOwned {
779 id owned = [self.ownedProp retain];
781 [_ownedProp release];
782 clang_analyzer_eval(owned == _ownedProp); // expected-warning{{TRUE}}
785 - (void)testPropertyAccessThenReleaseOwned2 {
786 id fromIvar = _ownedProp;
787 id owned = [self.ownedProp retain];
790 clang_analyzer_eval(owned == fromIvar); // expected-warning{{TRUE}}
793 - (void)testPropertyAccessThenReleaseUnowned {
794 id unowned = [self.unownedProp retain];
796 [_unownedProp release]; // FIXME-warning{{not owned}}
799 - (void)testPropertyAccessThenReleaseUnowned2 {
800 id fromIvar = _unownedProp;
801 id unowned = [self.unownedProp retain];
803 clang_analyzer_eval(unowned == fromIvar); // expected-warning{{TRUE}}
804 [fromIvar release]; // FIXME-warning{{not owned}}
807 - (void)testPropertyAccessThenReleaseManual {
808 id prop = [self.manualProp retain];
810 [_manualProp release]; // no-warning
813 - (void)testPropertyAccessThenReleaseManual2 {
814 id fromIvar = _manualProp;
815 id prop = [self.manualProp retain];
817 clang_analyzer_eval(prop == fromIvar); // expected-warning{{TRUE}}
818 [fromIvar release]; // no-warning
821 - (void)testPropertyAccessThenReleaseCF {
822 CFTypeRef owned = CFRetain(self.cfProp);
824 CFRelease(_cfProp); // no-warning
825 clang_analyzer_eval(owned == _cfProp); // expected-warning{{TRUE}}
828 - (void)testPropertyAccessThenReleaseCF2 {
829 CFTypeRef fromIvar = _cfProp;
830 CFTypeRef owned = CFRetain(self.cfProp);
833 clang_analyzer_eval(owned == fromIvar); // expected-warning{{TRUE}}
836 - (void)testPropertyAccessThenReleaseReadonly {
837 id prop = [self.readonlyProp retain];
839 [_readonlyProp release]; // no-warning
842 - (void)testPropertyAccessThenReleaseReadonly2 {
843 id fromIvar = _readonlyProp;
844 id prop = [self.readonlyProp retain];
846 clang_analyzer_eval(prop == fromIvar); // expected-warning{{TRUE}}
847 [fromIvar release]; // no-warning
850 - (void)testPropertyAccessThenReleaseImplicitManual {
851 id prop = [self.implicitManualProp retain];
853 [_implicitManualProp release]; // no-warning
856 - (void)testPropertyAccessThenReleaseImplicitManual2 {
857 id fromIvar = _implicitManualProp;
858 id prop = [self.implicitManualProp retain];
860 clang_analyzer_eval(prop == fromIvar); // expected-warning{{TRUE}}
861 [fromIvar release]; // no-warning
864 - (void)testPropertyAccessThenReleaseImplicitSynth {
865 id prop = [self.implicitSynthProp retain];
867 [_implicitSynthProp release]; // FIXME-warning{{not owned}}
870 - (void)testPropertyAccessThenReleaseImplicitSynth2 {
871 id fromIvar = _implicitSynthProp;
872 id prop = [self.implicitSynthProp retain];
874 clang_analyzer_eval(prop == fromIvar); // expected-warning{{TRUE}}
875 [fromIvar release]; // FIXME-warning{{not owned}}
878 - (id)getUnownedFromProperty {
880 [_ownedProp autorelease];
881 return _ownedProp; // no-warning
884 - (id)transferUnownedFromProperty {
886 [_ownedProp autorelease];
887 return [_ownedProp autorelease]; // no-warning
890 - (id)transferOwnedFromProperty __attribute__((ns_returns_retained)) {
892 [_ownedProp autorelease];
893 return _ownedProp; // no-warning
896 - (void)testAssignOwned:(id)newValue {
897 _ownedProp = newValue;
898 [_ownedProp release]; // FIXME: no-warning{{not owned}}
901 - (void)testAssignUnowned:(id)newValue {
902 _unownedProp = newValue;
903 [_unownedProp release]; // FIXME: no-warning{{not owned}}
906 - (void)testAssignIvarOnly:(id)newValue {
907 _ivarOnly = newValue;
908 [_ivarOnly release]; // FIXME: no-warning{{not owned}}
911 - (void)testAssignCF:(CFTypeRef)newValue {
913 CFRelease(_cfProp); // FIXME: no-warning{{not owned}}
916 - (void)testAssignReadonly:(id)newValue {
917 _readonlyProp = newValue;
918 [_readonlyProp release]; // FIXME: no-warning{{not owned}}
921 - (void)testAssignImplicitManual:(id)newValue {
922 _implicitManualProp = newValue;
923 [_implicitManualProp release]; // FIXME: no-warning{{not owned}}
926 - (void)testAssignImplicitSynth:(id)newValue {
927 _implicitSynthProp = newValue;
928 [_implicitSynthProp release]; // FIXME: no-warning{{not owned}}
931 - (void)testAssignOwnedOkay:(id)newValue {
932 _ownedProp = [newValue retain];
933 [_ownedProp release]; // no-warning
936 - (void)testAssignUnownedOkay:(id)newValue {
937 _unownedProp = [newValue retain];
938 [_unownedProp release]; // no-warning
941 - (void)testAssignIvarOnlyOkay:(id)newValue {
942 _ivarOnly = [newValue retain];
943 [_ivarOnly release]; // no-warning
946 - (void)testAssignCFOkay:(CFTypeRef)newValue {
947 _cfProp = CFRetain(newValue);
948 CFRelease(_cfProp); // no-warning
951 - (void)testAssignReadonlyOkay:(id)newValue {
952 _readonlyProp = [newValue retain];
953 [_readonlyProp release]; // FIXME: no-warning{{not owned}}
956 - (void)testAssignImplicitManualOkay:(id)newValue {
957 _implicitManualProp = [newValue retain];
958 [_implicitManualProp release]; // FIXME: no-warning{{not owned}}
961 - (void)testAssignImplicitSynthOkay:(id)newValue {
962 _implicitSynthProp = [newValue retain];
963 [_implicitSynthProp release]; // FIXME: no-warning{{not owned}}
966 // rdar://problem/19862648
967 - (void)establishIvarIsNilDuringLoops {
968 extern id getRandomObject();
970 int i = 4; // Must be at least 4 to trigger the bug.
973 if (getRandomObject())
976 x = getRandomObject();
981 // rdar://problem/20335433
982 - (void)retainIvarAndInvalidateSelf {
983 extern void invalidate(id);
984 [_unownedProp retain];
986 [_unownedProp release]; // no-warning
992 @property(nonatomic, readonly) int value;
995 @implementation Wrapper
999 void testNoCrashWhenAccessPropertyAndThereAreNoDirectBindingsAtAll() {