[cfe-commits] r133535 - in /cfe/trunk: lib/Sema/SemaExprObjC.cpp test/CodeGenObjC/arc-unbridged-cast.m
Fariborz Jahanian
fjahanian at apple.com
Tue Jun 21 12:42:38 PDT 2011
Author: fjahanian
Date: Tue Jun 21 14:42:38 2011
New Revision: 133535
URL: http://llvm.org/viewvc/llvm-project?rev=133535&view=rev
Log:
objc-arc: Add support for unbridged cast of
__builtin___CFStringMakeConstantString and CF typed function calls
with explicit cf_returns_retained/cf_returns_not_retained attributes.
// rdar://9544832
Modified:
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/CodeGenObjC/arc-unbridged-cast.m
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=133535&r1=133534&r2=133535&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Tue Jun 21 14:42:38 2011
@@ -1552,36 +1552,56 @@
bool
Sema::ValidObjCARCNoBridgeCastExpr(Expr *&Exp, QualType castType) {
- Expr *NewExp = Exp->IgnoreParenImpCasts();
+ Expr *NewExp = Exp->IgnoreParenCasts();
- if (!isa<ObjCMessageExpr>(NewExp) && !isa<ObjCPropertyRefExpr>(NewExp))
+ if (!isa<ObjCMessageExpr>(NewExp) && !isa<ObjCPropertyRefExpr>(NewExp)
+ && !isa<CallExpr>(NewExp))
return false;
ObjCMethodDecl *method = 0;
+ bool MethodReturnsPlusOne = false;
+
if (ObjCPropertyRefExpr *PRE = dyn_cast<ObjCPropertyRefExpr>(NewExp)) {
method = PRE->getExplicitProperty()->getGetterMethodDecl();
}
- else {
- ObjCMessageExpr *ME = cast<ObjCMessageExpr>(NewExp);
+ else if (ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(NewExp))
method = ME->getMethodDecl();
+ else {
+ CallExpr *CE = cast<CallExpr>(NewExp);
+ Decl *CallDecl = CE->getCalleeDecl();
+ if (!CallDecl)
+ return false;
+ if (CallDecl->hasAttr<CFReturnsNotRetainedAttr>())
+ return true;
+ MethodReturnsPlusOne = CallDecl->hasAttr<CFReturnsRetainedAttr>();
+ if (!MethodReturnsPlusOne) {
+ if (NamedDecl *ND = dyn_cast<NamedDecl>(CallDecl))
+ if (const IdentifierInfo *Id = ND->getIdentifier())
+ if (Id->isStr("__builtin___CFStringMakeConstantString"))
+ return true;
+ }
}
- if (!method)
- return false;
- if (method->hasAttr<CFReturnsNotRetainedAttr>())
- return true;
- bool MethodReturnsPlusOne = method->hasAttr<CFReturnsRetainedAttr>();
+
if (!MethodReturnsPlusOne) {
- ObjCMethodFamily family = method->getSelector().getMethodFamily();
- switch (family) {
- case OMF_alloc:
- case OMF_copy:
- case OMF_mutableCopy:
- case OMF_new:
- MethodReturnsPlusOne = true;
- break;
- default:
- break;
+ if (!method)
+ return false;
+ if (method->hasAttr<CFReturnsNotRetainedAttr>())
+ return true;
+ MethodReturnsPlusOne = method->hasAttr<CFReturnsRetainedAttr>();
+ if (!MethodReturnsPlusOne) {
+ ObjCMethodFamily family = method->getSelector().getMethodFamily();
+ switch (family) {
+ case OMF_alloc:
+ case OMF_copy:
+ case OMF_mutableCopy:
+ case OMF_new:
+ MethodReturnsPlusOne = true;
+ break;
+ default:
+ break;
+ }
}
}
+
if (MethodReturnsPlusOne) {
TypeSourceInfo *TSInfo =
Context.getTrivialTypeSourceInfo(castType, SourceLocation());
Modified: cfe/trunk/test/CodeGenObjC/arc-unbridged-cast.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-unbridged-cast.m?rev=133535&r1=133534&r2=133535&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/arc-unbridged-cast.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc-unbridged-cast.m Tue Jun 21 14:42:38 2011
@@ -24,4 +24,14 @@
- (void) setP : (CFStringRef)arg {}
@end
+// rdar://9544832
+CFStringRef SomeOtherFunc() __attribute__((cf_returns_retained));
+id MMM()
+{
+ id obj = (id)((CFStringRef) __builtin___CFStringMakeConstantString ("" "Some CF String" ""));
+ if (obj)
+ return (id) SomeOtherFunc();
+ return 0;
+}
+
// CHECK-NOT: call i8* @objc_retainAutoreleasedReturnValue
More information about the cfe-commits
mailing list