This patch fixes the ICE which occurs if the last expression is an array.
It ensures that the start and end values of the for loop expressions are
dereferenced.

gcc/m2/ChangeLog:

        PR modula2/120606
        * gm2-compiler/M2Quads.mod (ForLoopLastIterator): Dereference
        start and end expressions e1 and e2 respectively.

gcc/testsuite/ChangeLog:

        PR modula2/120606
        * gm2/pim/pass/forarray.mod: New test.

(cherry picked from commit 639a147414ab2b870f9482123fcaa1821e0d5475)

Signed-off-by: Gaius Mulley <gaiusm...@gmail.com>
---
 gcc/m2/gm2-compiler/M2Quads.mod         |  2 ++
 gcc/testsuite/gm2/pim/pass/forarray.mod | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+)
 create mode 100644 gcc/testsuite/gm2/pim/pass/forarray.mod

diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod
index b5455d09c66..748ce2498db 100644
--- a/gcc/m2/gm2-compiler/M2Quads.mod
+++ b/gcc/m2/gm2-compiler/M2Quads.mod
@@ -4646,6 +4646,8 @@ BEGIN
                    BySym) ;
       MetaErrorDecl (BySym, TRUE)
    ELSE
+      e1 := DereferenceLValue (e1tok, e1) ;
+      e2 := DereferenceLValue (e2tok, e2) ;
       GenQuadOTypetok (bytok, LastForIteratorOp, LastIterator,
                        Make2Tuple (e1, e2), BySym, FALSE, FALSE,
                        bytok, MakeVirtual2Tok (e1tok, e2tok), bytok)
diff --git a/gcc/testsuite/gm2/pim/pass/forarray.mod 
b/gcc/testsuite/gm2/pim/pass/forarray.mod
new file mode 100644
index 00000000000..e1b41e793bc
--- /dev/null
+++ b/gcc/testsuite/gm2/pim/pass/forarray.mod
@@ -0,0 +1,21 @@
+MODULE forarray ;
+
+
+VAR
+   array: ARRAY [0..10] OF CARDINAL ;
+
+
+PROCEDURE Init ;
+VAR
+   i, n: CARDINAL ;
+BEGIN
+   array[0] := 10 ;
+   n := 0 ;
+   FOR i := 1 TO array[n] DO
+   END
+END Init ;
+
+
+BEGIN
+   Init
+END forarray.
-- 
2.20.1

Reply via email to