[cfe-commits] r56793 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/block-as-object.m

Steve Naroff snaroff at apple.com
Mon Sep 29 11:10:19 PDT 2008


Author: snaroff
Date: Mon Sep 29 13:10:17 2008
New Revision: 56793

URL: http://llvm.org/viewvc/llvm-project?rev=56793&view=rev
Log:
Teach Sema::CheckAssignmentConstraints() to allow assignments between id and block pointer types (^{}).

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Sema/block-as-object.m

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Sep 29 13:10:17 2008
@@ -1653,10 +1653,15 @@
     if (isa<PointerType>(rhsType))
       return CheckPointerTypesForAssignment(lhsType, rhsType);
       
-    if (rhsType->getAsBlockPointerType())
+    if (rhsType->getAsBlockPointerType()) {
       if (lhsType->getAsPointerType()->getPointeeType()->isVoidType())
         return BlockVoidPointer;
-      
+
+      // Treat block pointers as objects.
+      if (getLangOptions().ObjC1 &&
+          lhsType == Context.getCanonicalType(Context.getObjCIdType()))
+        return Compatible;
+    }
     return Incompatible;
   }
 
@@ -1664,6 +1669,11 @@
     if (rhsType->isIntegerType())
       return IntToPointer;
     
+    // Treat block pointers as objects.
+    if (getLangOptions().ObjC1 &&
+        rhsType == Context.getCanonicalType(Context.getObjCIdType()))
+      return Compatible;
+
     if (rhsType->isBlockPointerType())
       return CheckBlockPointerTypesForAssignment(lhsType, rhsType);
       

Modified: cfe/trunk/test/Sema/block-as-object.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-as-object.m?rev=56793&r1=56792&r2=56793&view=diff

==============================================================================
--- cfe/trunk/test/Sema/block-as-object.m (original)
+++ cfe/trunk/test/Sema/block-as-object.m Mon Sep 29 13:10:17 2008
@@ -10,3 +10,11 @@
     id bar = [b copy];
 }
 
+void foo2(id b) {
+}
+
+void foo3(void (^block)(void)) {
+    foo2(block);
+    id x;
+    foo(x);
+}





More information about the cfe-commits mailing list