[cfe-commits] r91171 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/CodeGen/CGExprScalar.cpp lib/Sema/SemaCXXCast.cpp test/SemaObjCXX/blocks.mm

Fariborz Jahanian fjahanian at apple.com
Fri Dec 11 14:40:49 PST 2009


Author: fjahanian
Date: Fri Dec 11 16:40:48 2009
New Revision: 91171

URL: http://llvm.org/viewvc/llvm-project?rev=91171&view=rev
Log:
Patch to allow C-style cast from 'void *' to block pointer type.
(fixes radar 7465023).


Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
    cfe/trunk/lib/Sema/SemaCXXCast.cpp
    cfe/trunk/test/SemaObjCXX/blocks.mm

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=91171&r1=91170&r2=91171&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Dec 11 16:40:48 2009
@@ -1575,7 +1575,10 @@
 
     /// CK_AnyPointerToObjCPointerCast - Casting any pointer to objective-c 
     /// pointer
-    CK_AnyPointerToObjCPointerCast
+    CK_AnyPointerToObjCPointerCast,
+    /// CK_AnyPointerToBlockPointerCast - Casting any pointer to block 
+    /// pointer
+    CK_AnyPointerToBlockPointerCast
 
   };
 

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=91171&r1=91170&r2=91171&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Fri Dec 11 16:40:48 2009
@@ -560,6 +560,8 @@
     return "MemberPointerToBoolean";
   case CastExpr::CK_AnyPointerToObjCPointerCast:
     return "AnyPointerToObjCPointerCast";
+  case CastExpr::CK_AnyPointerToBlockPointerCast:
+    return "AnyPointerToBlockPointerCast";
   }
 
   assert(0 && "Unhandled cast kind!");

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=91171&r1=91170&r2=91171&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Fri Dec 11 16:40:48 2009
@@ -809,6 +809,7 @@
     break;
 
   case CastExpr::CK_AnyPointerToObjCPointerCast:
+  case CastExpr::CK_AnyPointerToBlockPointerCast:
   case CastExpr::CK_BitCast: {
     Value *Src = Visit(const_cast<Expr*>(E));
     return Builder.CreateBitCast(Src, ConvertType(DestTy));

Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=91171&r1=91170&r2=91171&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Fri Dec 11 16:40:48 2009
@@ -545,6 +545,11 @@
         Kind = CastExpr::CK_AnyPointerToObjCPointerCast;
         return TC_Success;
       }
+      else if (CStyle && DestType->isBlockPointerType()) {
+        // allow c-style cast of void * to block pointers.
+        Kind = CastExpr::CK_AnyPointerToBlockPointerCast;
+        return TC_Success;
+      }
     }
   }
 

Modified: cfe/trunk/test/SemaObjCXX/blocks.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/blocks.mm?rev=91171&r1=91170&r2=91171&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjCXX/blocks.mm (original)
+++ cfe/trunk/test/SemaObjCXX/blocks.mm Fri Dec 11 16:40:48 2009
@@ -44,3 +44,9 @@
     foo(N::X()); // okay
 }
 @end
+
+typedef signed char BOOL;
+void foo6(void *block) {  
+	void (^vb)(id obj, int idx, BOOL *stop) = (void (^)(id, int, BOOL *))block;
+    BOOL (^bb)(id obj, int idx, BOOL *stop) = (BOOL (^)(id, int, BOOL *))block;
+}





More information about the cfe-commits mailing list