// Also don't do anything if the ivar is unretained. If so, we know that
// there's no outstanding retain count for the value.
- if (const ObjCPropertyDecl *Prop = findPropForIvar(IRE->getDecl()))
- if (!Prop->isRetaining())
- return;
+ if (Kind == RetEffect::ObjC)
+ if (const ObjCPropertyDecl *Prop = findPropForIvar(IRE->getDecl()))
+ if (!Prop->isRetaining())
+ return;
// Note that this value has been loaded from an ivar.
C.addTransition(setRefBinding(State, Sym, RV->withIvarAccess()));
}
// Try to find the property associated with this ivar.
- const ObjCPropertyDecl *Prop = findPropForIvar(IRE->getDecl());
-
- if (Prop && !Prop->isRetaining())
- State = setRefBinding(State, Sym, PlusZero);
- else
+ if (Kind != RetEffect::ObjC) {
State = setRefBinding(State, Sym, PlusZero.withIvarAccess());
+ } else {
+ const ObjCPropertyDecl *Prop = findPropForIvar(IRE->getDecl());
+
+ if (Prop && !Prop->isRetaining())
+ State = setRefBinding(State, Sym, PlusZero);
+ else
+ State = setRefBinding(State, Sym, PlusZero.withIvarAccess());
+ }
C.addTransition(State);
}
void clang_analyzer_eval(int);
+typedef const void * CFTypeRef;
+extern CFTypeRef CFRetain(CFTypeRef cf);
+void CFRelease(CFTypeRef cf);
+
typedef signed char BOOL;
typedef unsigned int NSUInteger;
typedef struct _NSZone NSZone;
@property (strong) id ownedProp;
@property (unsafe_unretained) id unownedProp;
@property (nonatomic, strong) id manualProp;
+@property CFTypeRef cfProp;
@end
@implementation RetainCountTesting {
[_ivarOnly release]; // expected-warning{{used after it is released}}
}
+- (void)testOverreleaseCF {
+ CFRetain(_cfProp);
+ CFRelease(_cfProp);
+ CFRelease(_cfProp);
+ CFRelease(_cfProp); // expected-warning{{used after it is released}}
+}
+
- (void)testOverreleaseOwnedIvarUse {
[_ownedProp retain];
[_ownedProp release];
[_ivarOnly myMethod]; // expected-warning{{used after it is released}}
}
+- (void)testOverreleaseCFUse {
+ CFRetain(_cfProp);
+ CFRelease(_cfProp);
+ CFRelease(_cfProp);
+
+ extern void CFUse(CFTypeRef);
+ CFUse(_cfProp); // expected-warning{{used after it is released}}
+}
+
- (void)testOverreleaseOwnedIvarAutoreleaseOkay {
[_ownedProp retain];
[_ownedProp release];
[fromIvar release]; // no-warning
}
+- (void)testPropertyAccessThenReleaseCF {
+ CFTypeRef owned = CFRetain(self.cfProp);
+ CFRelease(owned);
+ CFRelease(_cfProp); // no-warning
+ clang_analyzer_eval(owned == _cfProp); // expected-warning{{TRUE}}
+}
+
+- (void)testPropertyAccessThenReleaseCF2 {
+ CFTypeRef fromIvar = _cfProp;
+ CFTypeRef owned = CFRetain(self.cfProp);
+ CFRelease(owned);
+ CFRelease(fromIvar);
+ clang_analyzer_eval(owned == fromIvar); // expected-warning{{TRUE}}
+}
+
- (id)getUnownedFromProperty {
[_ownedProp retain];
[_ownedProp autorelease];
[_ivarOnly release]; // FIXME: no-warning{{not owned}}
}
+- (void)testAssignCF:(CFTypeRef)newValue {
+ _cfProp = newValue;
+ CFRelease(_cfProp); // FIXME: no-warning{{not owned}}
+}
+
- (void)testAssignOwnedOkay:(id)newValue {
_ownedProp = [newValue retain];
[_ownedProp release]; // no-warning
[_ivarOnly release]; // no-warning
}
+- (void)testAssignCFOkay:(CFTypeRef)newValue {
+ _cfProp = CFRetain(newValue);
+ CFRelease(_cfProp); // no-warning
+}
+
// rdar://problem/19862648
- (void)establishIvarIsNilDuringLoops {
extern id getRandomObject();