Refine the type of the first parameter to block invoke functions.
WIP. I have yet to find the magic incantation to get the structure
type to be defined. If someone has a pointer, love to hear it.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84590 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp
index 736425e..5998493 100644
--- a/lib/CodeGen/CGBlocks.cpp
+++ b/lib/CodeGen/CGBlocks.cpp
@@ -632,11 +632,15 @@
const BlockDecl *BD = BExpr->getBlockDecl();
+ IdentifierInfo *II
+ = &CGM.getContext().Idents.get(".block_descriptor");
+
+ QualType ParmTy = getContext().getBlockParmType();
// FIXME: This leaks
ImplicitParamDecl *SelfDecl =
ImplicitParamDecl::Create(getContext(), 0,
- SourceLocation(), 0,
- getContext().getPointerType(getContext().VoidTy));
+ SourceLocation(), II,
+ ParmTy);
Args.push_back(std::make_pair(SelfDecl, SelfDecl->getType()));
BlockStructDecl = SelfDecl;
@@ -701,6 +705,22 @@
FinishFunction(cast<CompoundStmt>(BExpr->getBody())->getRBracLoc());
+ // And now finish off the type for the parameter, since now we know
+ // BlockDeclRefDecls is complete.
+ getContext().completeBlockParmType(ParmTy, BlockDeclRefDecls);
+
+#define REV2
+#ifdef REV2
+ TagDecl *TD = ParmTy->getPointeeType()->getAs<RecordType>()->getDecl();
+ CGM.UpdateCompletedType(TD);
+#else
+ TagDecl *TD = ParmTy->getPointeeType()->getAs<RecordType>()->getDecl();
+ TagDecl::redecl_iterator rdi = TD->redecls_begin();
+ ++rdi;
+ TD = *rdi;
+ CGM.UpdateCompletedType(TD);
+#endif
+
// The runtime needs a minimum alignment of a void *.
uint64_t MinAlign = getContext().getTypeAlign(getContext().VoidPtrTy) / 8;
BlockOffset = llvm::RoundUpToAlignment(BlockOffset, MinAlign);