This patch fixes an ICE which occurs if a constant char is assigned
into an integer array.  The fix it to introduce type checking in
M2GenGCC.mod:CodeXIndr.

gcc/m2/ChangeLog:

        PR modula2/120389
        * gm2-compiler/M2GenGCC.mod (CodeXIndr): Check to see that
        the type of left is assignment compatible with the type of
        right.

gcc/testsuite/ChangeLog:

        PR modula2/120389
        * gm2/iso/fail/badarray3.mod: New test.

(cherry picked from commit 895a8abad245365940939911e3d0de850522791e)

Signed-off-by: Gaius Mulley <gaiusm...@gmail.com>
---
 gcc/m2/gm2-compiler/M2GenGCC.mod         | 8 ++++++++
 gcc/testsuite/gm2/iso/fail/badarray3.mod | 7 +++++++
 2 files changed, 15 insertions(+)
 create mode 100644 gcc/testsuite/gm2/iso/fail/badarray3.mod

diff --git a/gcc/m2/gm2-compiler/M2GenGCC.mod b/gcc/m2/gm2-compiler/M2GenGCC.mod
index bc1d588fce6..2dfa566664a 100644
--- a/gcc/m2/gm2-compiler/M2GenGCC.mod
+++ b/gcc/m2/gm2-compiler/M2GenGCC.mod
@@ -8229,6 +8229,14 @@ BEGIN
    type := SkipType (type) ;
    DeclareConstant (rightpos, right) ;
    DeclareConstructor (rightpos, quad, right) ;
+   IF StrictTypeChecking AND
+      (NOT AssignmentTypeCompatible (xindrpos, "", GetType (left), right))
+   THEN
+      MetaErrorT2 (tokenno,
+                   'assignment check caught mismatch between {%1Ead} and 
{%2ad}',
+                   left, right) ;
+      SubQuad (quad)
+   END ;
    IF IsProcType(SkipType(type))
    THEN
       BuildAssignmentStatement (location, BuildIndirect (location, Mod2Gcc 
(left), GetPointerType ()), Mod2Gcc (right))
diff --git a/gcc/testsuite/gm2/iso/fail/badarray3.mod 
b/gcc/testsuite/gm2/iso/fail/badarray3.mod
new file mode 100644
index 00000000000..be53d21e74f
--- /dev/null
+++ b/gcc/testsuite/gm2/iso/fail/badarray3.mod
@@ -0,0 +1,7 @@
+MODULE badarray3 ;
+
+VAR
+   x: ARRAY [1..5] OF INTEGER ;
+BEGIN
+   x[1] := 'c';
+END badarray3.
-- 
2.20.1

Reply via email to