https://gcc.gnu.org/g:895a8abad245365940939911e3d0de850522791e
commit r16-832-g895a8abad245365940939911e3d0de850522791e Author: Gaius Mulley <gaiusm...@gmail.com> Date: Thu May 22 22:03:22 2025 +0100 PR modula2/120389 ICE if assigning a constant char to an integer array 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 <gaiusm...@gmail.com> Diff: --- gcc/m2/gm2-compiler/M2GenGCC.mod | 8 ++++++++ gcc/testsuite/gm2/iso/fail/badarray3.mod | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/gcc/m2/gm2-compiler/M2GenGCC.mod b/gcc/m2/gm2-compiler/M2GenGCC.mod index bc1d588fce6e..2dfa566664a4 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 000000000000..be53d21e74f3 --- /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.