PR modula2/114929 for loop fails to iterate down to zero when using a cardinal type
There is a bug in the for loop control code which is exposed when an
unsigned type is used in the iterator variable. See
gm2/pim/run/pass/testforloopzero[234].mod. The bug is in the
calculation of the last iterator value. The bug fix is to avoid using
negative expressions when calculating the last iterator value with a
negative step value. This patch detects if e1, e2, step value are all
constant, in which case the ztype is used internally and there is no
overflow. If the last iterator value is held in a variable then it
uses a different method to calculate the last iterator depending upon
the sign of the step value.
gcc/m2/ChangeLog:
PR modula2/114929
* gm2-compiler/M2LangDump.mod (GenQualidentSymString): Add
missing return result into identstr.
* gm2-compiler/M2Quads.mod (ForLoopLastIteratorVariable): New
procedure.
(ForLoopLastIteratorConstant): Ditto.
(ForLoopLastIterator): Ditto.
(BuildForToByDo): Remove LastIterator calculation and call
ForLoopLastIterator instead.
(FinalValue): Replace with ...
(LastIterator): ... this.
gcc/testsuite/ChangeLog:
PR modula2/114929
* gm2/pim/run/pass/testforloopzero.mod: New test.
* gm2/pim/run/pass/testforloopzero2.mod: New test.
* gm2/pim/run/pass/testforloopzero3.mod: New test.
* gm2/pim/run/pass/testforloopzero4.mod: New test.