Cope with llvm's reference to bool type of 'i1' vs. clang's
type of 'i8' for the same for __block variables of
type bool. refixes radar 8382559.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113015 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 06c657f..b4d0e13 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -335,6 +335,23 @@
llvm::Value *Value = EmitExprForReferenceBinding(*this, E, ReferenceTemporary,
ReferenceTemporaryDtor,
InitializedDecl);
+ if (E->getType()->isBooleanType()) {
+ // special handling for __block variable of bool type bound to
+ // a reference type.
+ bool block_byref_var = false;
+ if (const BlockDeclRefExpr *BE = dyn_cast<BlockDeclRefExpr>(E))
+ block_byref_var = BE->isByRef();
+ else if (const DeclRefExpr *BD = dyn_cast<DeclRefExpr>(E)) {
+ const NamedDecl *ND = BD->getDecl();
+ if (const VarDecl *VD = dyn_cast<VarDecl>(ND))
+ block_byref_var = VD->hasAttr<BlocksAttr>();
+ }
+ if (block_byref_var) {
+ const llvm::Type *T = ConvertTypeForMem(E->getType());
+ T = llvm::PointerType::getUnqual(T);
+ Value = Builder.CreateBitCast(Value, T);
+ }
+ }
if (!ReferenceTemporaryDtor)
return RValue::get(Value);