Declare extern const/immutable globals as IR constants (issue #2849) (#2852)

This commit is contained in:
Martin Kinkelin 2018-09-27 00:02:49 +02:00 committed by GitHub
parent e9a49f28b2
commit bc24e53565
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View file

@ -893,8 +893,10 @@ void DtoResolveVariable(VarDeclaration *vd) {
// 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();
// We also do so for forward-declared (extern) globals, just like clang.
const bool isLLConst = (vd->isConst() || vd->isImmutable()) &&
((vd->_init && !vd->_init->isVoidInitializer()) ||
(vd->storage_class & STCextern));
assert(!vd->ir->isInitialized());
if (gIR->dmodule) {