X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fcoptstop.c;h=f00410fa5e251a40d4d3fcd32ff903f95f6021b2;hb=35e1184901ca38bdb2e56d154ed3b71f6096eacc;hp=620a73504e52d7aba8fe303dcb61605846d32af7;hpb=5175f95341e23ce0e38b88ae96ee6c445a63f5b5;p=cc65 diff --git a/src/cc65/coptstop.c b/src/cc65/coptstop.c index 620a73504..f00410fa5 100644 --- a/src/cc65/coptstop.c +++ b/src/cc65/coptstop.c @@ -1724,7 +1724,8 @@ unsigned OptStackOps (CodeSeg* S) { unsigned Changes = 0; /* Number of changes in one run */ StackOpData Data; - unsigned I; + int I; + int OldEntryCount; /* Old number of entries */ enum { Initialize, @@ -1756,7 +1757,7 @@ unsigned OptStackOps (CodeSeg* S) * intermediate code for zero page use. */ I = 0; - while (I < CS_GetEntryCount (S)) { + while (I < (int)CS_GetEntryCount (S)) { /* Get the next entry */ CodeEntry* E = CS_GetEntry (S, I); @@ -1890,6 +1891,9 @@ unsigned OptStackOps (CodeSeg* S) Data.OpEntry = CS_GetEntry (S, Data.OpIndex); Data.NextEntry = CS_GetNextEntry (S, Data.OpIndex); + /* Remember the current number of code lines */ + OldEntryCount = CS_GetEntryCount (S); + /* Adjust stack offsets to account for the upcoming removal */ AdjustStackOffset (&Data, 2); @@ -1901,12 +1905,17 @@ unsigned OptStackOps (CodeSeg* S) /* Call the optimizer function */ Changes += Data.OptFunc->Func (&Data); + /* Since the function may have added or deleted entries, + * correct the index. + */ + I += CS_GetEntryCount (S) - OldEntryCount; + /* Regenerate register info */ CS_GenRegInfo (S); /* Done */ State = Initialize; - break; + continue; }