[cfe-commits] r133469 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Sema/SemaExprObjC.cpp test/SemaObjC/arc-unbridged-cast.m

Fariborz Jahanian fjahanian at apple.com
Mon Jun 20 13:54:42 PDT 2011


Author: fjahanian
Date: Mon Jun 20 15:54:42 2011
New Revision: 133469

URL: http://llvm.org/viewvc/llvm-project?rev=133469&view=rev
Log:
objc-arc: allow explicit unbridged casts if the source of the cast is a
message sent to an objc method (or property access)
// rdar://9474349

Added:
    cfe/trunk/test/SemaObjC/arc-unbridged-cast.m
Modified:
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaExprObjC.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=133469&r1=133468&r2=133469&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Jun 20 15:54:42 2011
@@ -5613,7 +5613,11 @@
   ExprResult CXXCheckCStyleCast(SourceRange R, QualType CastTy, ExprValueKind &VK,
                                 Expr *CastExpr, CastKind &Kind,
                                 CXXCastPath &BasePath, bool FunctionalStyle);
-  
+    
+  /// \brief Checks for valid expressions which can be cast to an ObjC
+  /// pointer without needing a bridge cast.
+  bool ValidObjCARCNoBridgeCastExpr(const Expr *Exp);
+    
   /// \brief Checks for invalid conversions and casts between
   /// retainable pointers and other pointer kinds.
   void CheckObjCARCConversion(SourceRange castRange, QualType castType, 

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=133469&r1=133468&r2=133469&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Mon Jun 20 15:54:42 2011
@@ -1550,6 +1550,12 @@
   };
 }
 
+bool
+Sema::ValidObjCARCNoBridgeCastExpr(const Expr *Exp) {
+  Exp = Exp->IgnoreParenImpCasts();
+  return isa<ObjCMessageExpr>(Exp) || isa<ObjCPropertyRefExpr>(Exp);
+}
+
 void 
 Sema::CheckObjCARCConversion(SourceRange castRange, QualType castType,
                              Expr *castExpr, CheckedConversionKind CCK) {
@@ -1606,6 +1612,10 @@
     
     if (castType->isObjCARCBridgableType() && 
         castExprType->isCARCBridgableType()) {
+      // explicit unbridged casts are allowed if the source of the cast is a 
+      // message sent to an objc method (or property access)
+      if (ValidObjCARCNoBridgeCastExpr(castExpr))
+        return;
       Diag(loc, diag::err_arc_cast_requires_bridge)
         << 2
         << castExprType

Added: cfe/trunk/test/SemaObjC/arc-unbridged-cast.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-unbridged-cast.m?rev=133469&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/arc-unbridged-cast.m (added)
+++ cfe/trunk/test/SemaObjC/arc-unbridged-cast.m Mon Jun 20 15:54:42 2011
@@ -0,0 +1,18 @@
+// // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -verify %s
+// rdar://9744349
+
+typedef const struct __CFString * CFStringRef;
+
+ at interface I 
+ at property CFStringRef P;
+ at end
+
+ at implementation I
+ at synthesize P;
+- (id) Meth {
+    I* p1 = (id)[p1 P];
+    id p2 = (__bridge_transfer id)[p1 P];
+    id p3 = (__bridge I*)[p1 P];
+    return (id) p1.P;
+}
+ at end





More information about the cfe-commits mailing list