mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-14 11:53:13 +01:00
Store bools as i8.
I really hope we can refactor this to use a less leaky abstraction later – it should at least be possible to merge voidToI8 and i1ToI8.
This commit is contained in:
@@ -18,18 +18,36 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool checkVarValueType(LLType* t, bool extraDeref)
|
||||
{
|
||||
if (extraDeref)
|
||||
{
|
||||
llvm::PointerType* pt = llvm::dyn_cast<llvm::PointerType>(t);
|
||||
if (!pt) return false;
|
||||
|
||||
t = pt->getElementType();
|
||||
}
|
||||
|
||||
llvm::PointerType* pt = llvm::dyn_cast<llvm::PointerType>(t);
|
||||
if (!pt) return false;
|
||||
|
||||
// bools should not be stored as i1 any longer.
|
||||
if (pt->getElementType() == llvm::Type::getInt1Ty(gIR->context()))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DVarValue::DVarValue(Type* t, VarDeclaration* vd, LLValue* llvmValue)
|
||||
: DValue(t), var(vd), val(llvmValue)
|
||||
{
|
||||
assert(isaPointer(llvmValue));
|
||||
assert(!isSpecialRefVar(vd) ||
|
||||
isaPointer(isaPointer(llvmValue)->getElementType()));
|
||||
assert(checkVarValueType(llvmValue->getType(), isSpecialRefVar(vd)));
|
||||
}
|
||||
|
||||
DVarValue::DVarValue(Type* t, LLValue* llvmValue)
|
||||
: DValue(t), var(0), val(llvmValue)
|
||||
{
|
||||
assert(isaPointer(llvmValue));
|
||||
assert(checkVarValueType(llvmValue->getType(), false));
|
||||
}
|
||||
|
||||
LLValue* DVarValue::getLVal()
|
||||
@@ -50,7 +68,17 @@ LLValue* DVarValue::getRVal()
|
||||
|
||||
if (DtoIsPassedByRef(type->toBasetype()))
|
||||
return storage;
|
||||
return DtoLoad(storage);
|
||||
|
||||
llvm::Value* rawValue = DtoLoad(storage);
|
||||
|
||||
if (type->toBasetype()->ty == Tbool)
|
||||
{
|
||||
assert(rawValue->getType() == llvm::Type::getInt8Ty(gIR->context()));
|
||||
return gIR->ir->CreateTrunc(rawValue,
|
||||
llvm::Type::getInt1Ty(gIR->context()));
|
||||
}
|
||||
|
||||
return rawValue;
|
||||
}
|
||||
|
||||
LLValue* DVarValue::getRefStorage()
|
||||
|
||||
Reference in New Issue
Block a user