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

Mike Stump mrs at apple.com
Fri Mar 6 18:53:19 PST 2009


Author: mrs
Date: Fri Mar  6 20:53:18 2009
New Revision: 66320

URL: http://llvm.org/viewvc/llvm-project?rev=66320&view=rev
Log:
codegen support for dispose helpers for block literals.

Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.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=66320&r1=66319&r2=66320&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Fri Mar  6 20:53:18 2009
@@ -802,7 +802,29 @@
                                           FunctionDecl::Static, false,
                                           true);
   CGF.StartFunction(FD, R, Fn, Args, SourceLocation());
-  // EmitStmt(BExpr->getBody());
+
+  llvm::Value *SrcObj = CGF.GetAddrOfLocalVar(Src);
+  llvm::Type *PtrPtrT;
+  PtrPtrT = llvm::PointerType::get(llvm::PointerType::get(T, 0), 0);
+  SrcObj = Builder.CreateBitCast(SrcObj, PtrPtrT);
+  SrcObj = Builder.CreateLoad(SrcObj);
+
+  for (unsigned i=0; i < NoteForHelper.size(); ++i) {
+    int flag = NoteForHelper[i].flag;
+    int index = NoteForHelper[i].index;
+
+    if ((NoteForHelper[i].flag & BLOCK_FIELD_IS_BYREF)
+        || NoteForHelper[i].RequiresCopying) {
+      llvm::Value *Srcv = SrcObj;
+      Srcv = Builder.CreateStructGEP(Srcv, index);
+      Srcv = Builder.CreateBitCast(Srcv,
+                                   llvm::PointerType::get(PtrToInt8Ty, 0));
+      Srcv = Builder.CreateLoad(Srcv);
+
+      BuildBlockRelease(Srcv, flag);
+    }
+  }
+
   CGF.FinishFunction();
 
   return llvm::ConstantExpr::getBitCast(Fn, PtrToInt8Ty);

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

==============================================================================
--- cfe/trunk/test/CodeGen/blocks-1.c (original)
+++ cfe/trunk/test/CodeGen/blocks-1.c Fri Mar  6 20:53:18 2009
@@ -1,5 +1,5 @@
 // RUN: clang %s -emit-llvm -o %t -fblocks -f__block &&
-// RUN: grep "_Block_object_dispose" %t | count 6 &&
+// RUN: grep "_Block_object_dispose" %t | count 10 &&
 // RUN: grep "__copy_helper_block_" %t | count 6 &&
 // RUN: grep "__destroy_helper_block_" %t | count 6 &&
 // RUN: grep "__Block_byref_id_object_copy_" %t | count 2 &&





More information about the cfe-commits mailing list