summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Stump <mrs@apple.com>2009-03-21 21:00:35 +0000
committerMike Stump <mrs@apple.com>2009-03-21 21:00:35 +0000
commitefd7caa8257ff25a9cedd19697a18ca388b8e9f2 (patch)
tree9970ce23613e0c757aad1189bf329d2d45ab1ebe
parent221c9a55785c58d12fcd53cb83a4459383613333 (diff)
downloadbcm5719-llvm-efd7caa8257ff25a9cedd19697a18ca388b8e9f2.tar.gz
bcm5719-llvm-efd7caa8257ff25a9cedd19697a18ca388b8e9f2.zip
Fixup codegen for nested block literals so that we generate
copy_helpers and dispose_helpers as necessary for them. llvm-svn: 67453
-rw-r--r--clang/lib/CodeGen/CGBlocks.cpp6
-rw-r--r--clang/lib/CodeGen/CGDecl.cpp2
-rw-r--r--clang/test/CodeGen/blocks-1.c14
3 files changed, 14 insertions, 8 deletions
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index c233ff38545..5780fc2958f 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -254,7 +254,6 @@ llvm::Value *CodeGenFunction::BuildBlockLiteralTmp(const BlockExpr *BE) {
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 @@ llvm::Value *CodeGenFunction::BuildBlockLiteralTmp(const BlockExpr *BE) {
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 @@ llvm::Value *CodeGenFunction::GetAddrOfBlockDecl(const BlockDeclRefExpr *E) {
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);
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index eb2fe4f5020..8a4febeecfb 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -334,8 +334,6 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
int flag = 0;
int flags = 0;
- // The block literal will need a copy/destroy helper.
- BlockHasCopyDispose = true;
needsDispose = true;
if (Ty->isBlockPointerType()) {
diff --git a/clang/test/CodeGen/blocks-1.c b/clang/test/CodeGen/blocks-1.c
index ae63e73a18e..54a83515680 100644
--- a/clang/test/CodeGen/blocks-1.c
+++ b/clang/test/CodeGen/blocks-1.c
@@ -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 @@ void test1() {
printf("a is %d, b is %d\n", a, b);
}
-
void test2() {
__block int a;
a=1;
@@ -55,6 +54,11 @@ void test5() {
^{ (void)i; }();
}
+void test6() {
+ __block int i;
+ ^{ i=1; }();
+}
+
int main() {
int rv = 0;
test1();
OpenPOWER on IntegriCloud