Hack to make nested struct .init results an rvalue.

The code still needs closer scrunity, as the 'nested' test
from the DMD testsuite doesn't fully pass yet.
This commit is contained in:
David Nadlinger
2013-01-11 21:34:45 +01:00
parent 7a4c378788
commit b99b78558b
6 changed files with 46 additions and 15 deletions

View File

@@ -2923,6 +2923,21 @@ DValue* StructLiteralExp::toElem(IRState* p)
Logger::print("StructLiteralExp::toElem: %s @ %s\n", toChars(), type->toChars());
LOG_SCOPE;
if (sinit)
{
// Copied from VarExp::toElem, need to clean this mess up.
Type* sdecltype = sinit->type->toBasetype();
Logger::print("Sym: type = %s\n", sdecltype->toChars());
assert(sdecltype->ty == Tstruct);
TypeStruct* ts = static_cast<TypeStruct*>(sdecltype);
assert(ts->sym);
ts->sym->codegen(Type::sir);
LLValue* initsym = ts->sym->ir.irStruct->getInitSymbol();
initsym = DtoBitCast(initsym, DtoType(ts->pointerTo()));
return new DVarValue(type, initsym);
}
// make sure the struct is fully resolved
sd->codegen(Type::sir);
@@ -3020,6 +3035,18 @@ LLConstant* StructLiteralExp::toConstElem(IRState* p)
Logger::print("StructLiteralExp::toConstElem: %s @ %s\n", toChars(), type->toChars());
LOG_SCOPE;
if (sinit)
{
// Copied from VarExp::toConstElem, need to clean this mess up.
Type* sdecltype = sinit->type->toBasetype();
Logger::print("Sym: type=%s\n", sdecltype->toChars());
assert(sdecltype->ty == Tstruct);
TypeStruct* ts = static_cast<TypeStruct*>(sdecltype);
ts->sym->codegen(Type::sir);
return ts->sym->ir.irStruct->getDefaultInit();
}
// make sure the struct is resolved
sd->codegen(Type::sir);