Do not re-codegen struct literals on taking address of globals.

The AST the frontend generates is arguably invalid, but we
have to deal with that.

Fixes DMD testcase 'interpret'.
This commit is contained in:
David Nadlinger
2013-06-16 01:02:46 +02:00
parent 68798f06c8
commit 897c4382af

View File

@@ -1231,6 +1231,24 @@ DValue* AddrExp::toElem(IRState* p)
{
IF_LOG Logger::println("AddrExp::toElem: %s @ %s", toChars(), type->toChars());
LOG_SCOPE;
// The address of a StructLiteralExp can in fact be a global variable, check
// for that instead of re-codegening the literal.
if (e1->op == TOKstructliteral)
{
IF_LOG Logger::println("is struct literal");
StructLiteralExp* se = static_cast<StructLiteralExp*>(e1);
// DMD uses origin here as well, necessary to handle messed-up AST on
// forward references.
if (se->origin->globalVar)
{
IF_LOG Logger::cout() << "returning address of global: " <<
*se->globalVar << '\n';
return new DImValue(type, DtoBitCast(se->origin->globalVar, DtoType(type)));
}
}
DValue* v = e1->toElem(p);
if (v->isField()) {
Logger::println("is field");