[cfe-commits] r67696 - in /cfe/trunk: lib/CodeGen/CGBlocks.cpp lib/CodeGen/CodeGenFunction.h test/CodeGen/blocks-1.c

Mike Stump mrs at apple.com
Wed Mar 25 10:58:25 PDT 2009


Author: mrs
Date: Wed Mar 25 12:58:24 2009
New Revision: 67696

URL: http://llvm.org/viewvc/llvm-project?rev=67696&view=rev
Log:
Fixup codegen for block literals that bleed copy/dispose information
from previous block literals.

Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h
    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=67696&r1=67695&r2=67696&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Wed Mar 25 12:58:24 2009
@@ -35,7 +35,8 @@
               llvm::cl::init(true));
 
 llvm::Constant *CodeGenFunction::
-BuildDescriptorBlockDecl(uint64_t Size, const llvm::StructType* Ty,
+BuildDescriptorBlockDecl(bool BlockHasCopyDispose, uint64_t Size,
+                         const llvm::StructType* Ty,
                          std::vector<HelperInfo> *NoteForHelper) {
   const llvm::Type *UnsignedLongTy
     = CGM.getTypes().ConvertType(getContext().UnsignedLongTy);
@@ -155,18 +156,20 @@
     // __invoke
     uint64_t subBlockSize, subBlockAlign;
     llvm::SmallVector<const Expr *, 8> subBlockDeclRefDecls;
+    bool subBlockHasCopyDispose = false;
     llvm::Function *Fn
       = CodeGenFunction(CGM).GenerateBlockFunction(BE, Info, CurFuncDecl, LocalDeclMap,
                                                    subBlockSize,
                                                    subBlockAlign,
                                                    subBlockDeclRefDecls,
-                                                   BlockHasCopyDispose);
+                                                   subBlockHasCopyDispose);
+    BlockHasCopyDispose |= subBlockHasCopyDispose;
     Elts[3] = Fn;
 
     if (!Enable__block && BlockHasCopyDispose)
       ErrorUnsupported(BE, "block literal that requires copy/dispose");
 
-    if (BlockHasCopyDispose)
+    if (subBlockHasCopyDispose)
       flags |= BLOCK_HAS_COPY_DISPOSE;
 
     // __isa
@@ -186,7 +189,8 @@
 
     if (subBlockDeclRefDecls.size() == 0) {
       // __descriptor
-      Elts[4] = BuildDescriptorBlockDecl(subBlockSize, 0, 0);
+      assert(subBlockHasCopyDispose == false);
+      Elts[4] = BuildDescriptorBlockDecl(subBlockHasCopyDispose, subBlockSize, 0, 0);
 
       // Optimize to being a global block.
       Elts[0] = CGM.getNSConcreteGlobalBlock();
@@ -318,7 +322,8 @@
     NoteForHelper.resize(helpersize);
 
     // __descriptor
-    llvm::Value *Descriptor = BuildDescriptorBlockDecl(subBlockSize, Ty,
+    llvm::Value *Descriptor = BuildDescriptorBlockDecl(subBlockHasCopyDispose,
+                                                       subBlockSize, Ty,
                                                        &NoteForHelper);
     Descriptor = Builder.CreateBitCast(Descriptor, PtrToInt8Ty);
     Builder.CreateStore(Descriptor, Builder.CreateStructGEP(V, 4, "block.tmp"));

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=67696&r1=67695&r2=67696&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Wed Mar 25 12:58:24 2009
@@ -267,7 +267,8 @@
   //===--------------------------------------------------------------------===//
 
   llvm::Value *BuildBlockLiteralTmp(const BlockExpr *);
-  llvm::Constant *BuildDescriptorBlockDecl(uint64_t Size,
+  llvm::Constant *BuildDescriptorBlockDecl(bool BlockHasCopyDispose,
+                                           uint64_t Size,
                                            const llvm::StructType *,
                                            std::vector<HelperInfo> *);
 

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

==============================================================================
--- cfe/trunk/test/CodeGen/blocks-1.c (original)
+++ cfe/trunk/test/CodeGen/blocks-1.c Wed Mar 25 12:58:24 2009
@@ -57,6 +57,7 @@
 void test6() {
   __block int i;
   ^{ i=1; }();
+ ^{};
 }
 
 int main() {





More information about the cfe-commits mailing list