Do not emit globals with void initializer as LLVM constants

Fixes things like `const(Foo) f = void; static shared this() { f = …; }`.
This commit is contained in:
David Nadlinger 2015-07-08 02:34:48 +02:00
parent f336ff9ee5
commit f7c3fc4ef3

View file

@ -929,7 +929,11 @@ void DtoResolveVariable(VarDeclaration* vd)
Logger::println("parent: null");
}
const bool isLLConst = (vd->isConst() || vd->isImmutable()) && vd->init;
// If a const/immutable value has a proper initializer (not "= void"),
// it cannot be assigned again in a static constructor. Thus, we can
// emit it as read-only data.
const bool isLLConst = (vd->isConst() || vd->isImmutable()) &&
vd->init && !vd->init->isVoidInitializer();
assert(!vd->ir.isInitialized());
if (gIR->dmodule)