[cfe-commits] r139709 - in /cfe/trunk: lib/ARCMigrate/TransUnbridgedCasts.cpp test/ARCMT/Common.h test/ARCMT/nonobjc-to-objc-cast.m test/ARCMT/nonobjc-to-objc-cast.m.result
Argyrios Kyrtzidis
akyrtzi at gmail.com
Wed Sep 14 11:17:09 PDT 2011
Author: akirtzidis
Date: Wed Sep 14 13:17:09 2011
New Revision: 139709
URL: http://llvm.org/viewvc/llvm-project?rev=139709&view=rev
Log:
[arcmt] Use __bridge_retained when passing an objc object to a CF parameter
annotated with cf_consumed attribute.
Modified:
cfe/trunk/lib/ARCMigrate/TransUnbridgedCasts.cpp
cfe/trunk/test/ARCMT/Common.h
cfe/trunk/test/ARCMT/nonobjc-to-objc-cast.m
cfe/trunk/test/ARCMT/nonobjc-to-objc-cast.m.result
Modified: cfe/trunk/lib/ARCMigrate/TransUnbridgedCasts.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransUnbridgedCasts.cpp?rev=139709&r1=139708&r2=139709&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/TransUnbridgedCasts.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/TransUnbridgedCasts.cpp Wed Sep 14 13:17:09 2011
@@ -242,6 +242,11 @@
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) {
@@ -265,6 +270,29 @@
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))
Modified: cfe/trunk/test/ARCMT/Common.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/Common.h?rev=139709&r1=139708&r2=139709&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/Common.h (original)
+++ cfe/trunk/test/ARCMT/Common.h Wed Sep 14 13:17:09 2011
@@ -4,6 +4,8 @@
#define NS_AUTOMATED_REFCOUNT_UNAVAILABLE
#endif
+#define CF_CONSUMED __attribute__((cf_consumed))
+
#define nil ((void*) 0)
typedef int BOOL;
Modified: cfe/trunk/test/ARCMT/nonobjc-to-objc-cast.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/nonobjc-to-objc-cast.m?rev=139709&r1=139708&r2=139709&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/nonobjc-to-objc-cast.m (original)
+++ cfe/trunk/test/ARCMT/nonobjc-to-objc-cast.m Wed Sep 14 13:17:09 2011
@@ -40,6 +40,8 @@
}
@end
+extern void consumeParam(CFStringRef CF_CONSUMED p);
+
void f2(NSString *s) {
CFStringRef ref = [s string];
ref = (CFStringRef)[s string];
@@ -53,4 +55,7 @@
ref = CFRetain([s string]);
ref = CFRetain(s);
ref = [s retain];
+
+ consumeParam((CFStringRef)s);
+ consumeParam(s);
}
Modified: cfe/trunk/test/ARCMT/nonobjc-to-objc-cast.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/nonobjc-to-objc-cast.m.result?rev=139709&r1=139708&r2=139709&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/nonobjc-to-objc-cast.m.result (original)
+++ cfe/trunk/test/ARCMT/nonobjc-to-objc-cast.m.result Wed Sep 14 13:17:09 2011
@@ -40,6 +40,8 @@
}
@end
+extern void consumeParam(CFStringRef CF_CONSUMED p);
+
void f2(NSString *s) {
CFStringRef ref = (__bridge CFStringRef)([s string]);
ref = (__bridge CFStringRef)[s string];
@@ -53,4 +55,7 @@
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));
}
More information about the cfe-commits
mailing list