diff --git a/gen/arrays.cpp b/gen/arrays.cpp index a3921e3160..1c6d0b7d97 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -353,7 +353,7 @@ static void DtoSetArray(DValue *array, LLValue *dim, LLValue *ptr) { //////////////////////////////////////////////////////////////////////////////// LLConstant *DtoConstArrayInitializer(ArrayInitializer *arrinit, - Type *targetType) { + Type *targetType, const bool isCfile) { IF_LOG Logger::println("DtoConstArrayInitializer: %s | %s", arrinit->toChars(), targetType->toChars()); LOG_SCOPE; @@ -416,7 +416,7 @@ LLConstant *DtoConstArrayInitializer(ArrayInitializer *arrinit, static_cast(j)); } - LLConstant *c = DtoConstInitializer(val->loc, elemty, val); + LLConstant *c = DtoConstInitializer(val->loc, elemty, val, isCfile); assert(c); if (c->getType() != llelemty) { mismatch = true; @@ -443,7 +443,8 @@ LLConstant *DtoConstArrayInitializer(ArrayInitializer *arrinit, } if (!elemDefaultInit) { - elemDefaultInit = DtoConstInitializer(arrinit->loc, elemty); + elemDefaultInit = + DtoConstInitializer(arrinit->loc, elemty, nullptr, isCfile); if (elemDefaultInit->getType() != llelemty) { mismatch = true; } diff --git a/gen/arrays.h b/gen/arrays.h index 1e1e5c07b2..22da7d1a80 100644 --- a/gen/arrays.h +++ b/gen/arrays.h @@ -32,7 +32,8 @@ llvm::ArrayType *DtoStaticArrayType(Type *sarrayTy); /// Creates a (global) constant with the element data for the given arary /// initializer. targetType is explicit because the frontend sometimes emits /// ArrayInitializers for vectors typed as static arrays. -LLConstant *DtoConstArrayInitializer(ArrayInitializer *si, Type *targetType); +LLConstant *DtoConstArrayInitializer(ArrayInitializer *si, Type *targetType, + const bool isCfile); LLConstant *DtoConstSlice(LLConstant *dim, LLConstant *ptr, Type *type = nullptr); diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 0afe6188b8..ab07a63c74 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -1084,7 +1084,8 @@ LLValue *DtoRawVarDeclaration(VarDeclaration *var, LLValue *addr) { * INITIALIZER HELPERS ******************************************************************************/ -LLConstant *DtoConstInitializer(const Loc &loc, Type *type, Initializer *init) { +LLConstant *DtoConstInitializer(const Loc &loc, Type *type, Initializer *init, + const bool isCfile) { LLConstant *_init = nullptr; // may return zero if (!init) { if (type->toBasetype()->isTypeNoreturn()) { @@ -1093,7 +1094,7 @@ LLConstant *DtoConstInitializer(const Loc &loc, Type *type, Initializer *init) { _init = LLConstant::getNullValue(ty); } else { IF_LOG Logger::println("const default initializer for %s", type->toChars()); - Expression *initExp = defaultInit(type, loc); + Expression *initExp = defaultInit(type, loc, isCfile); _init = DtoConstExpInit(loc, type, initExp); } } else if (ExpInitializer *ex = init->isExpInitializer()) { @@ -1101,7 +1102,7 @@ LLConstant *DtoConstInitializer(const Loc &loc, Type *type, Initializer *init) { _init = DtoConstExpInit(loc, type, ex->exp); } else if (ArrayInitializer *ai = init->isArrayInitializer()) { Logger::println("const array initializer"); - _init = DtoConstArrayInitializer(ai, type); + _init = DtoConstArrayInitializer(ai, type, isCfile); } else if (init->isVoidInitializer()) { Logger::println("const void initializer"); LLType *ty = DtoMemType(type); diff --git a/gen/llvmhelpers.h b/gen/llvmhelpers.h index 6fe347df44..7c7565a9fc 100644 --- a/gen/llvmhelpers.h +++ b/gen/llvmhelpers.h @@ -120,7 +120,7 @@ LLValue *DtoRawVarDeclaration(VarDeclaration *var, LLValue *addr = nullptr); // initializer helpers LLConstant *DtoConstInitializer(const Loc &loc, Type *type, - Initializer *init = nullptr); + Initializer *init, bool isCfile); LLConstant *DtoConstExpInit(const Loc &loc, Type *targetType, Expression *exp); // getting typeinfo of type, base=true casts to object.TypeInfo diff --git a/gen/toconstelem.cpp b/gen/toconstelem.cpp index 5388d26c51..49577ddcd5 100644 --- a/gen/toconstelem.cpp +++ b/gen/toconstelem.cpp @@ -88,7 +88,8 @@ public: } else { vd->inuse++; // return the initializer - result = DtoConstInitializer(e->loc, e->type, vd->_init); + result = + DtoConstInitializer(e->loc, e->type, vd->_init, vd->isCsymbol()); vd->inuse--; } } diff --git a/ir/iraggr.cpp b/ir/iraggr.cpp index f32f21398d..917a7c73dd 100644 --- a/ir/iraggr.cpp +++ b/ir/iraggr.cpp @@ -147,16 +147,15 @@ add_zeros(llvm::SmallVectorImpl &constants, ////////////////////////////////////////////////////////////////////////////// LLConstant *IrAggr::getDefaultInitializer(VarDeclaration *field) { - if (field->_init) { - // Issue 9057 workaround caused by issue 14666 fix, see DMD upstream - // commit 069f570005. - if (field->semanticRun < PASS::semantic2done && field->_scope) { - semantic2(field, field->_scope); - } - return DtoConstInitializer(field->_init->loc, field->type, field->_init); + // Issue 9057 workaround caused by issue 14666 fix, see DMD upstream + // commit 069f570005. + if (field->_init && field->semanticRun < PASS::semantic2done && + field->_scope) { + semantic2(field, field->_scope); } - return DtoConstInitializer(field->loc, field->type); + return DtoConstInitializer(field->_init ? field->_init->loc : field->loc, + field->type, field->_init, field->isCsymbol()); } // return a constant array of type arrTypeD initialized with a constant value, diff --git a/ir/irvar.cpp b/ir/irvar.cpp index 6d99528f03..751528293a 100644 --- a/ir/irvar.cpp +++ b/ir/irvar.cpp @@ -130,7 +130,8 @@ void IrGlobal::define() { message("%s: `%s` is thread local", V->loc.toChars(), V->toChars()); } - LLConstant *initVal = DtoConstInitializer(V->loc, V->type, V->_init); + LLConstant *initVal = + DtoConstInitializer(V->loc, V->type, V->_init, V->isCsymbol()); // Set the initializer, swapping out the variable if the types do not // match.