Workaround for AA literal initialization ICE.

Just executing toConstElem speculatively in
AssocArrayLiteralExp::toElem probably isn't the best idea
anyway, I would not be surprised if there are other similar bugs.

GitHub: Fixes #248.
This commit is contained in:
David Nadlinger
2012-12-19 02:09:19 +01:00
parent 03c77865d0
commit e068df24b2
2 changed files with 13 additions and 1 deletions

View File

@@ -1293,6 +1293,18 @@ LLConstant* AddrExp::toConstElem(IRState* p)
// global variable
if (VarDeclaration* vd = vexp->var->isVarDeclaration())
{
if (!vd->isDataseg())
{
// Not sure if this can be triggered from user code, but it is
// needed for the current hacky implementation of
// AssocArrayLiteralExp::toElem, which requires on error
// gagging to check for constantness of the initializer.
error("cannot use address of non-global variable '%s' "
"as constant initializer", vd->toChars());
if (!global.gag) fatal();
return NULL;
}
vd->codegen(Type::sir);
LLConstant* llc = llvm::dyn_cast<LLConstant>(vd->ir.getIrValue());
assert(llc);