diff options
author | Gaius Mulley <gaiusmod2@gmail.com> | 2024-12-05 20:31:34 +0000 |
---|---|---|
committer | Gaius Mulley <gaiusmod2@gmail.com> | 2024-12-05 20:31:34 +0000 |
commit | 363382ac7c2b8f6a09415e905b349bb7eaeca38a (patch) | |
tree | b6a77838bedbd969f5ec35443fe2c5878071b84d /gcc | |
parent | b3cb0c3302a7c16e661a08c15c897c8f7bbb5d23 (diff) | |
download | gcc-363382ac7c2b8f6a09415e905b349bb7eaeca38a.zip gcc-363382ac7c2b8f6a09415e905b349bb7eaeca38a.tar.gz gcc-363382ac7c2b8f6a09415e905b349bb7eaeca38a.tar.bz2 |
PR modula2/117904: cc1gm2 ICE when compiling a const built from VAL and SIZE
This patch fixes an ICE which occurs when a positive ZType constant
increment is used during a FOR loop.
gcc/m2/ChangeLog:
PR modula2/117904
* gm2-compiler/M2GenGCC.mod (PerformLastForIterator): Add call to
BuildConvert when increment is > 0.
gcc/testsuite/ChangeLog:
PR modula2/117904
* gm2/iso/pass/forloopbyconst.mod: New test.
Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/m2/gm2-compiler/M2GenGCC.mod | 16 | ||||
-rw-r--r-- | gcc/testsuite/gm2/iso/pass/forloopbyconst.mod | 25 |
2 files changed, 38 insertions, 3 deletions
diff --git a/gcc/m2/gm2-compiler/M2GenGCC.mod b/gcc/m2/gm2-compiler/M2GenGCC.mod index b6e34e0..c5f5a78 100644 --- a/gcc/m2/gm2-compiler/M2GenGCC.mod +++ b/gcc/m2/gm2-compiler/M2GenGCC.mod @@ -541,9 +541,19 @@ BEGIN THEN (* If incr > 0 then LastIterator := ((e2-e1) DIV incr) * incr + e1. *) expr := BuildSub (location, e2tree, e1tree, FALSE) ; - expr := BuildDivFloor (location, expr, incrtree, FALSE) ; - expr := BuildMult (location, expr, incrtree, FALSE) ; - expr := BuildAdd (location, expr, e1tree, FALSE) + incrtree := BuildConvert (location, GetTreeType (expr), incrtree, FALSE) ; + IF TreeOverflow (incrtree) + THEN + MetaErrorT0 (lastpos, + 'the intemediate calculation for the last iterator value in the {%kFOR} loop has caused an overflow') ; + NoChange := FALSE ; + SubQuad (quad) ; + success := FALSE + ELSE + expr := BuildDivFloor (location, expr, incrtree, FALSE) ; + expr := BuildMult (location, expr, incrtree, FALSE) ; + expr := BuildAdd (location, expr, e1tree, FALSE) + END ELSE (* Else use LastIterator := e1 - ((e1-e2) DIV PositiveBy) * PositiveBy to avoid unsigned div signed arithmetic. *) diff --git a/gcc/testsuite/gm2/iso/pass/forloopbyconst.mod b/gcc/testsuite/gm2/iso/pass/forloopbyconst.mod new file mode 100644 index 0000000..c0a1a06 --- /dev/null +++ b/gcc/testsuite/gm2/iso/pass/forloopbyconst.mod @@ -0,0 +1,25 @@ +MODULE forloopbyconst ; + + +CONST + block = 4 ; + + +(* + init - +*) + +PROCEDURE init ; +VAR + i, n: CARDINAL ; +BEGIN + n := 10 ; + FOR i := 1 TO n BY block DO + + END +END init ; + + +BEGIN + init +END forloopbyconst. |