aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-09-10 01:32:12 +0000
committerAnders Carlsson <andersca@mac.com>2009-09-10 01:32:12 +0000
commit3604386e1eacbe9da4ab13a2648a44ca581057d3 (patch)
tree511dfa2c3e89c4eccf893a1c2619b9b4eb9415c1
parente2fd66418eca3d70cf6b62087d745d0c5181db69 (diff)
Make the forwarding member of block byref structs be a pointer to the block byref struct itself.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81423 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGDecl.cpp17
-rw-r--r--test/CodeGen/blocks-seq.c14
2 files changed, 19 insertions, 12 deletions
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp
index ec8f626df5..5abe31e252 100644
--- a/lib/CodeGen/CGDecl.cpp
+++ b/lib/CodeGen/CGDecl.cpp
@@ -223,8 +223,11 @@ const llvm::Type *CodeGenFunction::BuildByRefType(const ValueDecl *D) {
std::vector<const llvm::Type *> Types(needsCopyDispose*2+5);
const llvm::PointerType *PtrToInt8Ty
= llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
+
+ llvm::PATypeHolder ByRefTypeHolder = llvm::OpaqueType::get(VMContext);
+
Types[0] = PtrToInt8Ty;
- Types[1] = PtrToInt8Ty;
+ Types[1] = llvm::PointerType::getUnqual(ByRefTypeHolder);
Types[2] = llvm::Type::getInt32Ty(VMContext);
Types[3] = llvm::Type::getInt32Ty(VMContext);
if (needsCopyDispose) {
@@ -235,7 +238,14 @@ const llvm::Type *CodeGenFunction::BuildByRefType(const ValueDecl *D) {
assert((Align <= unsigned(Target.getPointerAlign(0))/8)
&& "Can't align more than pointer yet");
Types[needsCopyDispose*2 + 4] = LTy;
- return llvm::StructType::get(VMContext, Types, false);
+
+ const llvm::Type *T = llvm::StructType::get(VMContext, Types, false);
+
+ cast<llvm::OpaqueType>(ByRefTypeHolder.get())->refineAbstractTypeTo(T);
+ CGM.getModule().addTypeName("struct.__block_byref_" + D->getNameAsString(),
+ ByRefTypeHolder.get());
+
+ return ByRefTypeHolder.get();
}
/// EmitLocalBlockVarDecl - Emit code and set up an entry in LocalDeclMap for a
@@ -413,8 +423,7 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
V = Builder.CreateIntToPtr(V, PtrToInt8Ty, "isa");
Builder.CreateStore(V, isa_field);
- V = Builder.CreateBitCast(DeclPtr, PtrToInt8Ty, "forwarding");
- Builder.CreateStore(V, forwarding_field);
+ Builder.CreateStore(DeclPtr, forwarding_field);
V = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), flags);
Builder.CreateStore(V, flags_field);
diff --git a/test/CodeGen/blocks-seq.c b/test/CodeGen/blocks-seq.c
index eac2acd3dd..3ff241e3f6 100644
--- a/test/CodeGen/blocks-seq.c
+++ b/test/CodeGen/blocks-seq.c
@@ -2,14 +2,12 @@
// builds with and without asserts. We need a better solution for this.
// RUN: clang-cc -fblocks -triple x86_64-apple-darwin10 -emit-llvm-bc -o - %s | opt -strip | llvm-dis > %t &&
-// RUN: grep '%7 = call i32 (...)\* @rhs()' %t | count 1 &&
-// RUN: grep '%8 = getelementptr inbounds %0\* %1, i32 0, i32 1' %t | count 1 &&
-// RUN: grep '%9 = bitcast i8\*\* %8 to %0\*\*' %t | count 1 &&
-// RUN: grep '%10 = load %0\*\* %9' %t | count 1 &&
-// RUN: grep '%12 = call i32 (...)\* @rhs()' %t | count 1 &&
-// RUN: grep '%13 = getelementptr inbounds %0\* %1, i32 0, i32 1' %t | count 1 &&
-// RUN: grep '%14 = bitcast i8\*\* %13 to %0\*\*' %t | count 1 &&
-// RUN: grep '%15 = load %0\*\* %14' %t | count 1
+// RUN: grep '%6 = call i32 (...)\* @rhs()' %t | count 1 &&
+// RUN: grep '%7 = getelementptr inbounds %0\* %1, i32 0, i32 1' %t | count 1 &&
+// RUN: grep '%8 = load %0\*\* %7' %t | count 1 &&
+// RUN: grep '%10 = call i32 (...)\* @rhs()' %t | count 1 &&
+// RUN: grep '%11 = getelementptr inbounds %0\* %1, i32 0, i32 1' %t | count 1 &&
+// RUN: grep '%12 = load %0\*\* %11' %t | count 1
int rhs();