Skip to content

Commit

Permalink
Fix "Compiler fills INIT_ARRAY/FINI_ARRAY with useless zeroes" (#20639)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel authored Jan 7, 2025
1 parent 95145b4 commit ce1c49a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 12 additions & 0 deletions compiler/src/dmd/backend/dt.d
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,18 @@ nothrow:
if (!size)
return;

bool allZero = true;
foreach (i; 0 .. size)
{
if (ptr[i] != 0)
{
allZero = false;
break;
}
}
if (allZero)
return nzeros(size);

dt_t *dt;

if (size < dt_t.DTibytesMax)
Expand Down
7 changes: 2 additions & 5 deletions compiler/src/dmd/todt.d
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,8 @@ void Expression_toDt(Expression e, ref DtBuilder dtb)
void visitInteger(IntegerExp e)
{
//printf("IntegerExp.toDt() %d\n", e.op);
const sz = cast(uint)e.type.size();
if (auto value = e.getInteger())
dtb.nbytes(sz, cast(char*)&value);
else
dtb.nzeros(sz);
auto value = e.getInteger();
dtb.nbytes(cast(uint)e.type.size(), cast(char*) &value);
}

void visitReal(RealExp e)
Expand Down

0 comments on commit ce1c49a

Please sign in to comment.