Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/dmd/backend/backconfig.d
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ static if (TARGET_WINDOS)
{
config.exe = EX_WIN32;
config.ehmethod = useExceptions ? EHmethod.EH_WIN32 : EHmethod.EH_NONE;
if (mscoff)
config.flags |= CFGnoebp; // test suite fails without this
config.objfmt = mscoff ? OBJ_MSCOFF : OBJ_OMF;
if (mscoff)
config.flags |= CFGnoebp; // test suite fails without this
Expand Down
8 changes: 7 additions & 1 deletion src/dmd/backend/blockopt.d
Original file line number Diff line number Diff line change
Expand Up @@ -660,13 +660,19 @@ void blockopt(int iter)
blexit();
if (iter >= 2)
brmin(); // minimize branching
version (MARS)
// Switched to one block per Statement, do not undo it
enum merge = false;
else
enum merge = true;

Comment on lines +663 to +668
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it's going to come back to haunt you down the road 🤷

do
{
compdfo(); /* compute depth first order (DFO) */
elimblks(); /* remove blocks not in DFO */
assert(count < iterationLimit);
count++;
} while (mergeblks()); /* merge together blocks */
} while (merge && mergeblks()); // merge together blocks
} while (go.changes);

debug if (debugw)
Expand Down
5 changes: 4 additions & 1 deletion src/dmd/backend/cgcod.d
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ tryagain:
mfuncreg = fregsaved; // so we can see which are used
// (bit is cleared each time
// we use one)
assert(!(needframe && mfuncreg & mBP)); // needframe needs mBP

for (block* b = startblock; b; b = b.Bnext)
{
memset(&b.Bregcon,0,b.Bregcon.sizeof); // Clear out values in registers
Expand Down Expand Up @@ -1016,7 +1018,6 @@ else
// we need BP to reset the stack before return
// otherwise the return address is lost
needframe = 1;

}
else if (config.flags & CFGalwaysframe)
needframe = 1;
Expand All @@ -1034,7 +1035,9 @@ else
anyiasm ||
Alloca.size
)
{
needframe = 1;
}
}
if (refparam && (anyiasm || I16))
needframe = 1;
Expand Down
5 changes: 3 additions & 2 deletions src/dmd/backend/go.d
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,13 @@ else
// Each pass through the loop can reduce only one level of comma expression.
// The infinite loop check needs to take this into account.
// Add 100 just to give optimizer more rope to try to converge.
int iterationLimit = 0;
int iterationLimit = 100;
for (block* b = startblock; b; b = b.Bnext)
{
if (!b.Belem)
continue;
int d = el_countCommas(b.Belem) + 100;
++iterationLimit;
int d = el_countCommas(b.Belem);
if (d > iterationLimit)
iterationLimit = d;
}
Expand Down
6 changes: 3 additions & 3 deletions src/dmd/backend/gother.d
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ private bool copyPropWalk(elem *n,vec_t IN)
{
Symbol *v = n.EV.Vsym;

//printf("Checking copyprop for '%s', ty=x%x\n",v.Sident,n.Ety);
//printf("Checking copyprop for '%s', ty=x%x\n", v.Sident.ptr,n.Ety);
symbol_debug(v);
const ty = n.Ety;
uint sz = tysize(n.Ety);
Expand All @@ -1309,7 +1309,7 @@ private bool copyPropWalk(elem *n,vec_t IN)
csz = cast(uint)type_size(c.ET);
assert(cast(int)csz >= 0);

//printf("looking at: ("); WReqn(c); printf("), ty=x%x\n",c.EV.E1.Ety);
//printf(" looking at: ("); WReqn(c); printf("), ty=x%x\n",c.EV.E1.Ety);
/* Not only must symbol numbers match, but */
/* offsets too (in case of arrays) and sizes */
/* (in case of unions). */
Expand All @@ -1333,7 +1333,7 @@ private bool copyPropWalk(elem *n,vec_t IN)
{
debug if (debugc)
{
printf("Copyprop, from '%s'(%d) to '%s'(%d)\n",
printf("Copyprop, '%s'(%d) replaced with '%s'(%d)\n",
(v.Sident[0]) ? cast(char *)v.Sident.ptr : "temp".ptr, cast(int) v.Ssymnum,
(f.Sident[0]) ? cast(char *)f.Sident.ptr : "temp".ptr, cast(int) f.Ssymnum);
}
Expand Down
12 changes: 10 additions & 2 deletions src/dmd/backend/symbol.d
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,17 @@ bool Symbol_isAffected(const ref Symbol s)
if (s.Sflags & SFLunambig)
return false;

/* If it's immutable, it can't be affected
/* If it's immutable, it can't be affected.
*
* Disable this check because:
* 1. Symbol_isAffected is not used by copyprop() and should be.
* 2. Non-@safe functions can temporarilly cast away immutable.
* 3. Need to add an @safe flag to funcsym_p to enable this.
* 4. Const can be mutated by a separate view.
* Address this in a separate PR.
*/
if (s.ty() & (mTYconst | mTYimmutable))
if (0 &&
s.ty() & (mTYconst | mTYimmutable))
{
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions src/dmd/s2ir.d
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,11 @@ private extern (C++) class S2irVisitor : Visitor
incUsage(irs, s.loc);

block_appendexp(blx.curblock, toElemDtor(s.exp, irs));

// goto the next block
block* b = blx.curblock;
block_next(blx, BCgoto, null);
b.appendSucc(blx.curblock);
}
}

Expand Down
26 changes: 26 additions & 0 deletions test/runnable/test20855.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// https://issues.dlang.org/show_bug.cgi?id=20855

string exp()
{
string s = "a = b + c * d + a;";
foreach (i; 0 .. 12)
s = s ~ s;
return s;
}

int test()
{
auto a=1, b=2, c=3, d=4;
mixin(exp());
return a;
}

import core.stdc.stdio;

int main()
{
int a = test();
printf("a = %d\n", a);
assert(test() == 57345);
return 0;
}