Remove DtoCastNull, because DtoNullValue does the same thing (only better)

This commit is contained in:
Alexey Prokhin 2014-08-21 18:21:53 +04:00
parent 76f3fd02bd
commit 2214728efd
3 changed files with 9 additions and 40 deletions

View file

@ -530,7 +530,7 @@ void DtoAssign(Loc& loc, DValue* lhs, DValue* rhs, int op, bool canSkipPostblit)
// NULL VALUE HELPER // NULL VALUE HELPER
////////////////////////////////////////////////////////////////////////////////////////*/ ////////////////////////////////////////////////////////////////////////////////////////*/
DValue* DtoNullValue(Type* type) DValue* DtoNullValue(Type* type, Loc loc)
{ {
Type* basetype = type->toBasetype(); Type* basetype = type->toBasetype();
TY basety = basetype->ty; TY basety = basetype->ty;
@ -560,8 +560,11 @@ DValue* DtoNullValue(Type* type)
{ {
return new DNullValue(type, LLConstant::getNullValue(lltype)); return new DNullValue(type, LLConstant::getNullValue(lltype));
} }
else
llvm_unreachable("null not known for this type."); {
error(loc, "null not known for type '%s'", type->toChars());
fatal();
}
} }
@ -736,40 +739,6 @@ DValue* DtoCastDelegate(Loc& loc, DValue* val, Type* to)
} }
} }
DValue* DtoCastNull(Loc& loc, DValue* val, Type* to)
{
Type* totype = to->toBasetype();
LLType* tolltype = DtoType(to);
if (totype->ty == Tpointer || totype->ty == Tclass)
{
IF_LOG Logger::cout() << "cast null to pointer/class: " << *tolltype << '\n';
LLValue *rval = DtoBitCast(val->getRVal(), tolltype);
return new DImValue(to, rval);
}
if (totype->ty == Tarray)
{
IF_LOG Logger::cout() << "cast null to array: " << *tolltype << '\n';
LLValue *rval = val->getRVal();
rval = DtoBitCast(rval, DtoType(to->nextOf()->pointerTo()));
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());
fatal();
}
}
DValue* DtoCastVector(Loc& loc, DValue* val, Type* to) DValue* DtoCastVector(Loc& loc, DValue* val, Type* to)
{ {
assert(val->getType()->toBasetype()->ty == Tvector); assert(val->getType()->toBasetype()->ty == Tvector);
@ -875,7 +844,7 @@ DValue* DtoCast(Loc& loc, DValue* val, Type* to)
return DtoCastDelegate(loc, val, to); return DtoCastDelegate(loc, val, to);
} }
else if (fromtype->ty == Tnull) { else if (fromtype->ty == Tnull) {
return DtoCastNull(loc, val, to); return DtoNullValue(to, loc);
} }
else if (fromtype->ty == totype->ty) { else if (fromtype->ty == totype->ty) {
return val; return val;

View file

@ -90,7 +90,7 @@ DValue* DtoSymbolAddress(Loc& loc, Type* type, Declaration* decl);
llvm::Constant* DtoConstSymbolAddress(Loc& loc,Declaration* decl); llvm::Constant* DtoConstSymbolAddress(Loc& loc,Declaration* decl);
/// Create a null DValue. /// Create a null DValue.
DValue* DtoNullValue(Type* t); DValue* DtoNullValue(Type* t, Loc loc = Loc());
// casts // casts
DValue* DtoCastInt(Loc& loc, DValue* val, Type* to); DValue* DtoCastInt(Loc& loc, DValue* val, Type* to);

@ -1 +1 @@
Subproject commit 64233b6fb4e9e1730e677daee6d3a2bc214594d3 Subproject commit 9429b6cf5e15730f1cb7f8c9256155df2fdc4584