[cfe-commits] r67453 - in /cfe/trunk: lib/CodeGen/CGBlocks.cpp lib/CodeGen/CGDecl.cpp test/CodeGen/blocks-1.c

Mike Stump mrs at apple.com
Sat Mar 21 14:00:36 PDT 2009


Author: mrs
Date: Sat Mar 21 16:00:35 2009
New Revision: 67453

URL: http://llvm.org/viewvc/llvm-project?rev=67453&view=rev
Log:
Fixup codegen for nested block literals so that we generate
copy_helpers and dispose_helpers as necessary for them.

Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    cfe/trunk/lib/CodeGen/CGDecl.cpp
    cfe/trunk/test/CodeGen/blocks-1.c

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Sat Mar 21 16:00:35 2009
@@ -254,7 +254,6 @@
 
         if (LocalDeclMap[VD]) {
           if (BDRE->isByRef()) {
-            // FIXME: For only local, or all byrefs?
             NoteForHelper[helpersize].flag = BLOCK_FIELD_IS_BYREF |
               // FIXME: Someone double check this.
               (VD->getType().isObjCGCWeak() ? BLOCK_FIELD_IS_WEAK : 0);
@@ -272,6 +271,9 @@
                                                 false, false);
         }
         if (BDRE->isByRef()) {
+          NoteForHelper[helpersize].flag = BLOCK_FIELD_IS_BYREF |
+            // FIXME: Someone double check this.
+            (VD->getType().isObjCGCWeak() ? BLOCK_FIELD_IS_WEAK : 0);
           E = new (getContext())
             UnaryOperator(E, UnaryOperator::AddrOf,
                           getContext().getPointerType(E->getType()),
@@ -511,6 +513,8 @@
     uint64_t Align = getContext().getDeclAlignInBytes(E->getDecl());
     const llvm::Type *PtrStructTy
       = llvm::PointerType::get(BuildByRefType(E->getType(), Align), 0);
+    // The block literal will need a copy/destroy helper.
+    BlockHasCopyDispose = true;
     Ty = PtrStructTy;
     Ty = llvm::PointerType::get(Ty, 0);
     V = Builder.CreateBitCast(V, Ty);

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Sat Mar 21 16:00:35 2009
@@ -334,8 +334,6 @@
     int flag = 0;
     int flags = 0;
 
-    // The block literal will need a copy/destroy helper.
-    BlockHasCopyDispose = true;
     needsDispose = true;
 
     if (Ty->isBlockPointerType()) {

Modified: cfe/trunk/test/CodeGen/blocks-1.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/blocks-1.c?rev=67453&r1=67452&r2=67453&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/blocks-1.c (original)
+++ cfe/trunk/test/CodeGen/blocks-1.c Sat Mar 21 16:00:35 2009
@@ -1,11 +1,11 @@
 // RUN: clang %s -emit-llvm -o %t -fblocks -f__block &&
-// RUN: grep "_Block_object_dispose" %t | count 12 &&
-// RUN: grep "__copy_helper_block_" %t | count 8 &&
-// RUN: grep "__destroy_helper_block_" %t | count 8 &&
+// RUN: grep "_Block_object_dispose" %t | count 15 &&
+// RUN: grep "__copy_helper_block_" %t | count 12 &&
+// RUN: grep "__destroy_helper_block_" %t | count 12 &&
 // RUN: grep "__Block_byref_id_object_copy_" %t | count 2 &&
 // RUN: grep "__Block_byref_id_object_dispose_" %t | count 2 &&
 // RUN: grep "i32 135)" %t | count 2 &&
-// RUN: grep "_Block_object_assign" %t | count 7
+// RUN: grep "_Block_object_assign" %t | count 9
 
 #include <stdio.h>
 
@@ -20,7 +20,6 @@
   printf("a is %d, b is %d\n", a, b);
 }
 
-
 void test2() {
   __block int a;
   a=1;
@@ -55,6 +54,11 @@
   ^{ (void)i; }();
 }
 
+void test6() {
+  __block int i;
+  ^{ i=1; }();
+}
+
 int main() {
   int rv = 0;
   test1();





More information about the cfe-commits mailing list