mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-01 07:30:43 +03:00
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:
parent
dab538f76e
commit
4b1f5516fd
7 changed files with 22 additions and 18 deletions
|
@ -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<unsigned long long>(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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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--;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,16 +147,15 @@ add_zeros(llvm::SmallVectorImpl<llvm::Constant *> &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) {
|
||||
if (field->_init && field->semanticRun < PASS::semantic2done &&
|
||||
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,
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue