mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-02 08:01:11 +03:00
DtoCast: Implement struct repainting casts
The assoiative array case seems to be mostly triggered by some remaining parts of the old shared/immutable AA type canonicalization issue.
This commit is contained in:
parent
10d17e9c92
commit
994da2e98f
1 changed files with 25 additions and 4 deletions
|
@ -580,6 +580,23 @@ DValue *DtoCastVector(Loc &loc, DValue *val, Type *to) {
|
||||||
fatal();
|
fatal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DValue *DtoCastStruct(Loc &loc, DValue *val, Type *to) {
|
||||||
|
Type *const totype = to->toBasetype();
|
||||||
|
if (totype->ty == Tstruct) {
|
||||||
|
// This a cast to repaint a struct to another type, which the language
|
||||||
|
// allows for identical layouts (opCast() and so on have been lowered
|
||||||
|
// earlier by the frontend).
|
||||||
|
llvm::Value *rv = val->getRVal();
|
||||||
|
llvm::Value *result =
|
||||||
|
DtoBitCast(rv, DtoType(to)->getPointerTo(), rv->getName() + ".repaint");
|
||||||
|
return new DImValue(to, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
error(loc, "Internal Compiler Error: Invalid struct cast from '%s' to '%s'",
|
||||||
|
val->getType()->toChars(), to->toChars());
|
||||||
|
fatal();
|
||||||
|
}
|
||||||
|
|
||||||
DValue *DtoCast(Loc &loc, DValue *val, Type *to) {
|
DValue *DtoCast(Loc &loc, DValue *val, Type *to) {
|
||||||
Type *fromtype = val->getType()->toBasetype();
|
Type *fromtype = val->getType()->toBasetype();
|
||||||
Type *totype = to->toBasetype();
|
Type *totype = to->toBasetype();
|
||||||
|
@ -633,13 +650,17 @@ DValue *DtoCast(Loc &loc, DValue *val, Type *to) {
|
||||||
return DtoCastPtr(loc, val, to);
|
return DtoCastPtr(loc, val, to);
|
||||||
case Tdelegate:
|
case Tdelegate:
|
||||||
return DtoCastDelegate(loc, val, to);
|
return DtoCastDelegate(loc, val, to);
|
||||||
|
case Tstruct:
|
||||||
|
return DtoCastStruct(loc, val, to);
|
||||||
case Tnull:
|
case Tnull:
|
||||||
return DtoNullValue(to, loc);
|
return DtoNullValue(to, loc);
|
||||||
default:
|
case Taarray:
|
||||||
if (fromtype->ty == totype->ty) {
|
if (totype->ty == Taarray) {
|
||||||
// FIXME: This silently discards aggregate casts!
|
// Do nothing, the types will match up anyway.
|
||||||
return val;
|
return new DImValue(to, val->getRVal());
|
||||||
}
|
}
|
||||||
|
// fall-through
|
||||||
|
default:
|
||||||
error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(),
|
error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(),
|
||||||
to->toChars());
|
to->toChars());
|
||||||
fatal();
|
fatal();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue