зеркало из https://github.com/microsoft/clang-1.git
Truncate block variable of bool type to i1 when its
value is used. This matches with non-block variable use of bool type. (Fixes radar 8390062). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113027 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
030ef472f3
Коммит
469a20de75
|
@ -373,7 +373,7 @@ const llvm::Type *CodeGenFunction::BuildByRefType(const ValueDecl *D) {
|
|||
}
|
||||
|
||||
// T x;
|
||||
Types.push_back(ConvertType(Ty));
|
||||
Types.push_back(ConvertTypeForMem(Ty));
|
||||
|
||||
const llvm::Type *T = llvm::StructType::get(VMContext, Types, Packed);
|
||||
|
||||
|
|
|
@ -335,24 +335,6 @@ CodeGenFunction::EmitReferenceBindingToExpr(const Expr* E,
|
|||
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);
|
||||
|
||||
|
|
|
@ -1118,7 +1118,7 @@ Value *ScalarExprEmitter::VisitBlockDeclRefExpr(const BlockDeclRefExpr *E) {
|
|||
llvm::Value *V = CGF.GetAddrOfBlockDecl(E);
|
||||
if (E->getType().isObjCGCWeak())
|
||||
return CGF.CGM.getObjCRuntime().EmitObjCWeakRead(CGF, V);
|
||||
return Builder.CreateLoad(V, "tmp");
|
||||
return CGF.EmitLoadOfScalar(V, false, 0, E->getType());
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
|
@ -48,16 +48,23 @@ namespace radar8382559 {
|
|||
|
||||
int test3() {
|
||||
__attribute__((__blocks__(byref))) bool hasProperty = false;
|
||||
bool has = true;
|
||||
|
||||
bool (^b)() = ^ {
|
||||
func(hasProperty);
|
||||
if (hasProperty)
|
||||
hasProperty = 0;
|
||||
if (has)
|
||||
hasProperty = 1;
|
||||
return hasProperty;
|
||||
};
|
||||
func(hasProperty);
|
||||
func(has);
|
||||
b();
|
||||
if (hasProperty)
|
||||
hasProperty = 1;
|
||||
if (has)
|
||||
has = 2;
|
||||
return hasProperty = 1;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче