Skip to content

Commit 363382a

Browse files
author
Gaius Mulley
committed
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 <[email protected]>
1 parent b3cb0c3 commit 363382a

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

gcc/m2/gm2-compiler/M2GenGCC.mod

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,19 @@ BEGIN
541541
THEN
542542
(* If incr > 0 then LastIterator := ((e2-e1) DIV incr) * incr + e1. *)
543543
expr := BuildSub (location, e2tree, e1tree, FALSE) ;
544-
expr := BuildDivFloor (location, expr, incrtree, FALSE) ;
545-
expr := BuildMult (location, expr, incrtree, FALSE) ;
546-
expr := BuildAdd (location, expr, e1tree, FALSE)
544+
incrtree := BuildConvert (location, GetTreeType (expr), incrtree, FALSE) ;
545+
IF TreeOverflow (incrtree)
546+
THEN
547+
MetaErrorT0 (lastpos,
548+
'the intemediate calculation for the last iterator value in the {%kFOR} loop has caused an overflow') ;
549+
NoChange := FALSE ;
550+
SubQuad (quad) ;
551+
success := FALSE
552+
ELSE
553+
expr := BuildDivFloor (location, expr, incrtree, FALSE) ;
554+
expr := BuildMult (location, expr, incrtree, FALSE) ;
555+
expr := BuildAdd (location, expr, e1tree, FALSE)
556+
END
547557
ELSE
548558
(* Else use LastIterator := e1 - ((e1-e2) DIV PositiveBy) * PositiveBy
549559
to avoid unsigned div signed arithmetic. *)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
MODULE forloopbyconst ;
2+
3+
4+
CONST
5+
block = 4 ;
6+
7+
8+
(*
9+
init -
10+
*)
11+
12+
PROCEDURE init ;
13+
VAR
14+
i, n: CARDINAL ;
15+
BEGIN
16+
n := 10 ;
17+
FOR i := 1 TO n BY block DO
18+
19+
END
20+
END init ;
21+
22+
23+
BEGIN
24+
init
25+
END forloopbyconst.

0 commit comments

Comments
 (0)