Pass isCfile parameter for all defaultInit() calls, for some extra importC zero-init

Fixes dmd-testsuite's runnable/test22994.c.
This commit is contained in:
Martin Kinkelin 2022-04-30 19:53:22 +02:00
parent dab538f76e
commit 4b1f5516fd
7 changed files with 22 additions and 18 deletions

View file

@ -353,7 +353,7 @@ static void DtoSetArray(DValue *array, LLValue *dim, LLValue *ptr) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
LLConstant *DtoConstArrayInitializer(ArrayInitializer *arrinit, LLConstant *DtoConstArrayInitializer(ArrayInitializer *arrinit,
Type *targetType) { Type *targetType, const bool isCfile) {
IF_LOG Logger::println("DtoConstArrayInitializer: %s | %s", IF_LOG Logger::println("DtoConstArrayInitializer: %s | %s",
arrinit->toChars(), targetType->toChars()); arrinit->toChars(), targetType->toChars());
LOG_SCOPE; LOG_SCOPE;
@ -416,7 +416,7 @@ LLConstant *DtoConstArrayInitializer(ArrayInitializer *arrinit,
static_cast<unsigned long long>(j)); static_cast<unsigned long long>(j));
} }
LLConstant *c = DtoConstInitializer(val->loc, elemty, val); LLConstant *c = DtoConstInitializer(val->loc, elemty, val, isCfile);
assert(c); assert(c);
if (c->getType() != llelemty) { if (c->getType() != llelemty) {
mismatch = true; mismatch = true;
@ -443,7 +443,8 @@ LLConstant *DtoConstArrayInitializer(ArrayInitializer *arrinit,
} }
if (!elemDefaultInit) { if (!elemDefaultInit) {
elemDefaultInit = DtoConstInitializer(arrinit->loc, elemty); elemDefaultInit =
DtoConstInitializer(arrinit->loc, elemty, nullptr, isCfile);
if (elemDefaultInit->getType() != llelemty) { if (elemDefaultInit->getType() != llelemty) {
mismatch = true; mismatch = true;
} }

View file

@ -32,7 +32,8 @@ llvm::ArrayType *DtoStaticArrayType(Type *sarrayTy);
/// Creates a (global) constant with the element data for the given arary /// Creates a (global) constant with the element data for the given arary
/// initializer. targetType is explicit because the frontend sometimes emits /// initializer. targetType is explicit because the frontend sometimes emits
/// ArrayInitializers for vectors typed as static arrays. /// 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, LLConstant *DtoConstSlice(LLConstant *dim, LLConstant *ptr,
Type *type = nullptr); Type *type = nullptr);

View file

@ -1084,7 +1084,8 @@ LLValue *DtoRawVarDeclaration(VarDeclaration *var, LLValue *addr) {
* INITIALIZER HELPERS * 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 LLConstant *_init = nullptr; // may return zero
if (!init) { if (!init) {
if (type->toBasetype()->isTypeNoreturn()) { if (type->toBasetype()->isTypeNoreturn()) {
@ -1093,7 +1094,7 @@ LLConstant *DtoConstInitializer(const Loc &loc, Type *type, Initializer *init) {
_init = LLConstant::getNullValue(ty); _init = LLConstant::getNullValue(ty);
} else { } else {
IF_LOG Logger::println("const default initializer for %s", type->toChars()); 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); _init = DtoConstExpInit(loc, type, initExp);
} }
} else if (ExpInitializer *ex = init->isExpInitializer()) { } 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); _init = DtoConstExpInit(loc, type, ex->exp);
} else if (ArrayInitializer *ai = init->isArrayInitializer()) { } else if (ArrayInitializer *ai = init->isArrayInitializer()) {
Logger::println("const array initializer"); Logger::println("const array initializer");
_init = DtoConstArrayInitializer(ai, type); _init = DtoConstArrayInitializer(ai, type, isCfile);
} else if (init->isVoidInitializer()) { } else if (init->isVoidInitializer()) {
Logger::println("const void initializer"); Logger::println("const void initializer");
LLType *ty = DtoMemType(type); LLType *ty = DtoMemType(type);

View file

@ -120,7 +120,7 @@ LLValue *DtoRawVarDeclaration(VarDeclaration *var, LLValue *addr = nullptr);
// initializer helpers // initializer helpers
LLConstant *DtoConstInitializer(const Loc &loc, Type *type, LLConstant *DtoConstInitializer(const Loc &loc, Type *type,
Initializer *init = nullptr); Initializer *init, bool isCfile);
LLConstant *DtoConstExpInit(const Loc &loc, Type *targetType, Expression *exp); LLConstant *DtoConstExpInit(const Loc &loc, Type *targetType, Expression *exp);
// getting typeinfo of type, base=true casts to object.TypeInfo // getting typeinfo of type, base=true casts to object.TypeInfo

View file

@ -88,7 +88,8 @@ public:
} else { } else {
vd->inuse++; vd->inuse++;
// return the initializer // return the initializer
result = DtoConstInitializer(e->loc, e->type, vd->_init); result =
DtoConstInitializer(e->loc, e->type, vd->_init, vd->isCsymbol());
vd->inuse--; vd->inuse--;
} }
} }

View file

@ -147,16 +147,15 @@ add_zeros(llvm::SmallVectorImpl<llvm::Constant *> &constants,
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
LLConstant *IrAggr::getDefaultInitializer(VarDeclaration *field) { LLConstant *IrAggr::getDefaultInitializer(VarDeclaration *field) {
if (field->_init) {
// Issue 9057 workaround caused by issue 14666 fix, see DMD upstream // Issue 9057 workaround caused by issue 14666 fix, see DMD upstream
// commit 069f570005. // commit 069f570005.
if (field->semanticRun < PASS::semantic2done && field->_scope) { if (field->_init && field->semanticRun < PASS::semantic2done &&
field->_scope) {
semantic2(field, field->_scope); semantic2(field, field->_scope);
} }
return DtoConstInitializer(field->_init->loc, field->type, field->_init);
}
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, // return a constant array of type arrTypeD initialized with a constant value,

View file

@ -130,7 +130,8 @@ void IrGlobal::define() {
message("%s: `%s` is thread local", V->loc.toChars(), V->toChars()); 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 // Set the initializer, swapping out the variable if the types do not
// match. // match.