Fix casting typeof(null) to bool.

Covered by the DMD testsuite.
This commit is contained in:
David Nadlinger
2013-03-16 09:35:29 +01:00
parent 4a0746d53c
commit 82ba7fe548

View File

@@ -739,6 +739,14 @@ DValue* DtoCastNull(Loc& loc, DValue* val, Type* to)
rval = DtoAggrPair(DtoConstSize_t(0), rval, "null_array");
return new DImValue(to, rval);
}
else if (totype->ty == Tbool)
{
// In theory, we could return 'false' as a constant here, but DMD
// treats non-null values casted to typeof(null) as true.
LLValue* rval = val->getRVal();
LLValue* zero = LLConstant::getNullValue(rval->getType());
return new DImValue(to, gIR->ir->CreateICmpNE(rval, zero, "tmp"));
}
else
{
error(loc, "invalid cast from null to '%s'", to->toChars());