]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR modula2/120389 ICE if assigning a constant char to an integer array
authorGaius Mulley <gaiusmod2@gmail.com>
Thu, 22 May 2025 21:03:22 +0000 (22:03 +0100)
committerGaius Mulley <gaiusmod2@gmail.com>
Thu, 22 May 2025 21:03:22 +0000 (22:03 +0100)
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.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
gcc/m2/gm2-compiler/M2GenGCC.mod
gcc/testsuite/gm2/iso/fail/badarray3.mod [new file with mode: 0644]

index bc1d588fce6eac7491f8fa078a2038623f1af383..2dfa566664a489fb9cfc1df3270c7f81b25a18c9 100644 (file)
@@ -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 (file)
index 0000000..be53d21
--- /dev/null
@@ -0,0 +1,7 @@
+MODULE badarray3 ;
+
+VAR
+   x: ARRAY [1..5] OF INTEGER ;
+BEGIN
+   x[1] := 'c';
+END badarray3.