Fixes an obscure bug in importd block variable layout
information when imported variable is used
more than once. Originally though to be a bug in importing
block varibles. Fixes radar 8417746.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113675 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp
index 8254135..73074b6 100644
--- a/lib/CodeGen/CGObjCMac.cpp
+++ b/lib/CodeGen/CGObjCMac.cpp
@@ -1000,7 +1000,7 @@
/// definition is seen. The return value has type ProtocolPtrTy.
virtual llvm::Constant *GetOrEmitProtocolRef(const ObjCProtocolDecl *PD)=0;
virtual llvm::Constant *GCBlockLayout(CodeGen::CodeGenFunction &CGF,
- const llvm::SmallVectorImpl<const BlockDeclRefExpr *> &);
+ const llvm::SmallVectorImpl<const Expr *> &);
};
@@ -1663,11 +1663,11 @@
}
llvm::Constant *CGObjCCommonMac::GCBlockLayout(CodeGen::CodeGenFunction &CGF,
- const llvm::SmallVectorImpl<const BlockDeclRefExpr *> &DeclRefs) {
+ const llvm::SmallVectorImpl<const Expr *> &BlockLayout) {
llvm::Constant *NullPtr =
llvm::Constant::getNullValue(llvm::Type::getInt8PtrTy(VMContext));
if ((CGM.getLangOptions().getGCMode() == LangOptions::NonGC) ||
- DeclRefs.empty())
+ BlockLayout.empty())
return NullPtr;
bool hasUnion = false;
SkipIvars.clear();
@@ -1678,8 +1678,11 @@
// __isa is the first field in block descriptor and must assume by runtime's
// convention that it is GC'able.
IvarsInfo.push_back(GC_IVAR(0, 1));
- for (size_t i = 0; i < DeclRefs.size(); ++i) {
- const BlockDeclRefExpr *BDRE = DeclRefs[i];
+ for (size_t i = 0; i < BlockLayout.size(); ++i) {
+ const Expr *E = BlockLayout[i];
+ const BlockDeclRefExpr *BDRE = dyn_cast<BlockDeclRefExpr>(E);
+ if (!BDRE)
+ continue;
const ValueDecl *VD = BDRE->getDecl();
CharUnits Offset = CGF.BlockDecls[VD];
uint64_t FieldOffset = Offset.getQuantity();