if (implCE->getCastKind() == CK_ARCReclaimReturnedObject)
return rewriteToBridgedCast(E, OBC_Bridge);
}
+
+ bool isConsumed = false;
+ if (isPassedToCParamWithKnownOwnership(E, isConsumed))
+ return rewriteToBridgedCast(E, isConsumed ? OBC_BridgeRetained
+ : OBC_Bridge);
}
static ObjCMethodFamily getFamilyOfMessage(Expr *E) {
return false;
}
+ bool isPassedToCParamWithKnownOwnership(Expr *E, bool &isConsumed) const {
+ if (CallExpr *callE = dyn_cast_or_null<CallExpr>(
+ StmtMap->getParentIgnoreParenImpCasts(E)))
+ if (FunctionDecl *
+ FD = dyn_cast_or_null<FunctionDecl>(callE->getCalleeDecl())) {
+ unsigned i = 0;
+ for (unsigned e = callE->getNumArgs(); i != e; ++i) {
+ Expr *arg = callE->getArg(i);
+ if (arg == E || arg->IgnoreParenImpCasts() == E)
+ break;
+ }
+ if (i < callE->getNumArgs()) {
+ ParmVarDecl *PD = FD->getParamDecl(i);
+ if (PD->getAttr<CFConsumedAttr>()) {
+ isConsumed = true;
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
bool isSelf(Expr *E) const {
E = E->IgnoreParenLValueCasts();
if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
}
@end
+extern void consumeParam(CFStringRef CF_CONSUMED p);
+
void f2(NSString *s) {
CFStringRef ref = [s string];
ref = (CFStringRef)[s string];
ref = CFRetain([s string]);
ref = CFRetain(s);
ref = [s retain];
+
+ consumeParam((CFStringRef)s);
+ consumeParam(s);
}
}
@end
+extern void consumeParam(CFStringRef CF_CONSUMED p);
+
void f2(NSString *s) {
CFStringRef ref = (__bridge CFStringRef)([s string]);
ref = (__bridge CFStringRef)[s string];
ref = (__bridge_retained CFTypeRef)([s string]);
ref = (__bridge_retained CFTypeRef)(s);
ref = (__bridge_retained CFStringRef)(s);
+
+ consumeParam((__bridge_retained CFStringRef)s);
+ consumeParam((__bridge_retained CFStringRef)(s));
}