[Bug modula2/120389] Assigning a CHAR to an INTEGER crashes the compiler
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120389 --- Comment #10 from GCC Commits --- The releases/gcc-15 branch has been updated by Gaius Mulley : https://gcc.gnu.org/g:1e9255f7b35973686ea6e091d340259edb3ac4b1 commit r15-9984-g1e9255f7b35973686ea6e091d340259edb3ac4b1 Author: Gaius Mulley Date: Wed Jul 16 19:33:37 2025 +0100 [PATCH] PR modula2/120389 Assigning wrong type to an array causes an ICE Although cherry picked as described. The cherry pick does not include the command option (-fm2-strict-type-reason) introduced in: gcc/m2/gm2-lang.cc, gcc/m2/lang.opt and gcc/doc/gm2.texi from the original patch. This patch provides follow on fixes for undetected type violations which can occur then Lvalues are generated during assignment. For example array accesses and with statements. The type checker M2Check.mod has been overhauled and cleaned up. gcc/m2/ChangeLog: PR modula2/120389 * gm2-compiler/M2Check.def (AssignmentTypeCompatible): Add new parameter enableReason. * gm2-compiler/M2Check.mod (EquivalenceProcedure): New type. (falseReason2): New procedure function. (falseReason1): Ditto. (falseReason0): Ditto. (checkTypeEquivalence): Rewrite. (checkUnboundedArray): Ditto. (checkUnbounded): Ditto. (checkArrayTypeEquivalence): Ditto. (checkCharStringTypeEquivalence): Ditto. (buildError4): Add false reason. (buildError2): Ditto. (IsTyped): Use GetDType. (IsTypeEquivalence): New procedure function. (checkVarTypeEquivalence): Ditto. (checkVarEquivalence ): Rewrite. (checkConstMeta): Ditto. (checkEnumField): New procedure function. (checkEnumFieldEquivalence): Ditto. (checkSubrangeTypeEquivalence): Rewrite. (checkSystemEquivalence): Ditto. (checkTypeKindViolation): Ditto. (doCheckPair): Ditto. (InitEquivalenceArray): New procedure. (addEquivalence): Ditto. (checkProcType): Rewrite. (deconstruct): Deallocate reason string. (AssignmentTypeCompatible): Initialize reason and reasonEnable fields. (ParameterTypeCompatible): Ditto. (doExpressionTypeCompatible): Ditto. * gm2-compiler/M2GenGCC.mod (CodeIndrX) Rewrite. (CheckBinaryExpressionTypes): Rewrite and simplify now that the type checker is more robust. (CheckElementSetTypes): Ditto. (CodeXIndr): Add new range assignment type check. * gm2-compiler/M2MetaError.def: Correct comments. * gm2-compiler/M2Options.def (SetStrictTypeAssignment): New procedure. (SetStrictTypeReason): Ditto. * gm2-compiler/M2Options.mod: (SetStrictTypeAssignment): New procedure. (SetStrictTypeReason): Ditto. (StrictTypeReason): Initialize. (StrictTypeAssignment): Ditto. * gm2-compiler/M2Quads.mod (CheckBreak): Delete. (BreakQuad): New global variable. (BreakAtQuad): Delete. (gdbhook): New procedure. (BreakWhenQuadCreated): Ditto. (CheckBreak): Ditto. (Init): Call BreakWhenQuadCreated and gdbhook. (doBuildAssignment): Add type assignment range check. (CheckProcTypeAndProcedure): Only check if the procedure types differ. (doIndrX): Add type IndrX range check. (CheckReturnType): Add range return type check. * gm2-compiler/M2Range.def (InitTypesIndrXCheck): New procedure function. (InitTypesReturnTypeCheck): Ditto. * gm2-compiler/M2Range.mod (InitTypesIndrXCheck): New procedure function. (InitTypesReturnTypeCheck): Ditto. (HandlerExists): Add new clauses. (FoldAssignment): Pass extra FALSE parameter to AssignmentTypeCompatible. (FoldTypeReturnFunc): New procedure. (FoldTypeAssign): Ditto. (FoldTypeIndrX): Ditto. (CodeTypeAssign): Rewrite. (CodeTypeIndrX): New procedure. (CodeTypeReturnFunc): Ditto. (FoldTypeCheck): Add new case clauses. (CodeTypeCheck): Ditto. (FoldRangeCheckLower): Ditto. (IssueWarning): Ditto. * gm2-gcc/m2options.h (M2Options_SetStrictTypeAssignment): New function prototype. (M2Options_SetStrictTypeReason): Ditto. gcc/testsuite/ChangeLog: PR modula2/120389 * gm2/pim/fail/testcharint.mod: New test. * gm2/pim/fail/testindrx.mod: New test. * gm2/pim/pass/testxindr.mod: New test. * gm2/pim/pass/testxindr2.mod: New test. * g
[Bug modula2/120389] Assigning a CHAR to an INTEGER crashes the compiler
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120389 Gaius Mulley changed: What|Removed |Added Resolution|--- |FIXED Status|ASSIGNED|RESOLVED --- Comment #9 from Gaius Mulley --- Closing.
[Bug modula2/120389] Assigning a CHAR to an INTEGER crashes the compiler
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120389 --- Comment #8 from GCC Commits --- The releases/gcc-15 branch has been updated by Gaius Mulley : https://gcc.gnu.org/g:7dcb64479e0cc590641a505b8fe1fd542f22a38f commit r15-9980-g7dcb64479e0cc590641a505b8fe1fd542f22a38f Author: Gaius Mulley Date: Tue Jul 15 19:38:04 2025 +0100 [PATCH] 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. (cherry picked from commit 895a8abad245365940939911e3d0de850522791e) Signed-off-by: Gaius Mulley
[Bug modula2/120389] Assigning a CHAR to an INTEGER crashes the compiler
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120389 --- Comment #7 from GCC Commits --- The master branch has been updated by Gaius Mulley : https://gcc.gnu.org/g:e131ba3de5f487f5e957ba1b011c960fce557c7b commit r16-1026-ge131ba3de5f487f5e957ba1b011c960fce557c7b Author: Gaius Mulley Date: Sat May 31 01:53:48 2025 +0100 PR modula2/120389 Assigning wrong type to an array causes an ICE This patch provides follow on fixes for undetected type violations which can occur then Lvalues are generated during assignment. For example array accesses and with statements. The type checker M2Check.mod has been overhauled and cleaned up. gcc/ChangeLog: PR modula2/120389 * doc/gm2.texi (-fm2-strict-type-reason): Document new flag. gcc/m2/ChangeLog: PR modula2/120389 * gm2-compiler/M2Check.def (AssignmentTypeCompatible): Add new parameter enableReason. * gm2-compiler/M2Check.mod (EquivalenceProcedure): New type. (falseReason2): New procedure function. (falseReason1): Ditto. (falseReason0): Ditto. (checkTypeEquivalence): Rewrite. (checkUnboundedArray): Ditto. (checkUnbounded): Ditto. (checkArrayTypeEquivalence): Ditto. (checkCharStringTypeEquivalence): Ditto. (buildError4): Add false reason. (buildError2): Ditto. (IsTyped): Use GetDType. (IsTypeEquivalence): New procedure function. (checkVarTypeEquivalence): Ditto. (checkVarEquivalence ): Rewrite. (checkConstMeta): Ditto. (checkEnumField): New procedure function. (checkEnumFieldEquivalence): Ditto. (checkSubrangeTypeEquivalence): Rewrite. (checkSystemEquivalence): Ditto. (checkTypeKindViolation): Ditto. (doCheckPair): Ditto. (InitEquivalenceArray): New procedure. (addEquivalence): Ditto. (checkProcType): Rewrite. (deconstruct): Deallocate reason string. (AssignmentTypeCompatible): Initialize reason and reasonEnable fields. (ParameterTypeCompatible): Ditto. (doExpressionTypeCompatible): Ditto. * gm2-compiler/M2GenGCC.mod (CodeIndrX) Rewrite. (CheckBinaryExpressionTypes): Rewrite and simplify now that the type checker is more robust. (CheckElementSetTypes): Ditto. (CodeXIndr): Add new range assignment type check. * gm2-compiler/M2MetaError.def: Correct comments. * gm2-compiler/M2Options.def (SetStrictTypeAssignment): New procedure. (SetStrictTypeReason): Ditto. * gm2-compiler/M2Options.mod: (SetStrictTypeAssignment): New procedure. (SetStrictTypeReason): Ditto. (StrictTypeReason): Initialize. (StrictTypeAssignment): Ditto. * gm2-compiler/M2Quads.mod (CheckBreak): Delete. (BreakQuad): New global variable. (BreakAtQuad): Delete. (gdbhook): New procedure. (BreakWhenQuadCreated): Ditto. (CheckBreak): Ditto. (Init): Call BreakWhenQuadCreated and gdbhook. (doBuildAssignment): Add type assignment range check. (CheckProcTypeAndProcedure): Only check if the procedure types differ. (doIndrX): Add type IndrX range check. (CheckReturnType): Add range return type check. * gm2-compiler/M2Range.def (InitTypesIndrXCheck): New procedure function. (InitTypesReturnTypeCheck): Ditto. * gm2-compiler/M2Range.mod (InitTypesIndrXCheck): New procedure function. (InitTypesReturnTypeCheck): Ditto. (HandlerExists): Add new clauses. (FoldAssignment): Pass extra FALSE parameter to AssignmentTypeCompatible. (FoldTypeReturnFunc): New procedure. (FoldTypeAssign): Ditto. (FoldTypeIndrX): Ditto. (CodeTypeAssign): Rewrite. (CodeTypeIndrX): New procedure. (CodeTypeReturnFunc): Ditto. (FoldTypeCheck): Add new case clauses. (CodeTypeCheck): Ditto. (FoldRangeCheckLower): Ditto. (IssueWarning): Ditto. * gm2-gcc/m2options.h (M2Options_SetStrictTypeAssignment): New function prototype. (M2Options_SetStrictTypeReason): Ditto. * gm2-lang.cc (gm2_langhook_handle_option): New case clause OPT_fm2_strict_type_reason. * lang.opt (-fm2-strict-type-reason): New option. gcc/testsuite/ChangeLog: PR modula2/120389 * gm2/pim/fail/testcharint.mod: New test. * gm2/pim/fail/testindrx.mod: New test. * gm2/pim/pass/testxindr.mod: New test. * gm2/
[Bug modula2/120389] Assigning a CHAR to an INTEGER crashes the compiler
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120389 --- Comment #6 from Gaius Mulley --- When compiled with gm2 after the patch above has been applied, we get a clean compile. $ gm2 -c testxindr2.mod $ echo $? 0
[Bug modula2/120389] Assigning a CHAR to an INTEGER crashes the compiler
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120389 --- Comment #5 from Gaius Mulley --- Confirmed. Also this code provokes the bug: $ cat testxindr2.mod MODULE testxindr2 ; (*!m2iso+gm2*) CONST NulName = 0 ; TYPE Name = CARDINAL ; PROCEDURE set (VAR n: Name) ; BEGIN n := NulName END set ; VAR n: Name ; BEGIN set (n) END testxindr2. $ gm2 -c testxindr2.mod testxindr2.mod:10:6: error: In procedure ‘set’: assignment check caught mismatch between ‘n’ and ‘NulName’ 10 |n := NulName |~~^~
[Bug modula2/120389] Assigning a CHAR to an INTEGER crashes the compiler
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120389 --- Comment #4 from Gaius Mulley --- Created attachment 61551 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61551&action=edit Improved proposed fix This patch type checks lvalues within the becomes op. It also rewrites and tidies up the type checker adding optional detail on why the type violation occurred.
[Bug modula2/120389] Assigning a CHAR to an INTEGER crashes the compiler
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120389 --- Comment #3 from GCC Commits --- The master branch has been updated by Gaius Mulley : https://gcc.gnu.org/g:895a8abad245365940939911e3d0de850522791e commit r16-832-g895a8abad245365940939911e3d0de850522791e Author: Gaius Mulley 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
[Bug modula2/120389] Assigning a CHAR to an INTEGER crashes the compiler
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120389 --- Comment #2 from Gaius Mulley --- Created attachment 61494 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61494&action=edit Proposed fix which incompatible types in Xindr Here is a proposed patch. $ cat badarray.mod MODULE badarray3 ; VAR x: ARRAY [1..5] OF INTEGER ; BEGIN x[1] := 'c'; END badarray3. $ gm2 badarray3.mod badarray3.mod: In function ‘_M2_badarray3_init’: badarray3.mod:6:9: error: assignment check caught mismatch between expression and ‘c’ 6 |x[1] := 'c'; |~^~
[Bug modula2/120389] Assigning a CHAR to an INTEGER crashes the compiler
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120389 Gaius Mulley changed: What|Removed |Added Ever confirmed|0 |1 Status|UNCONFIRMED |ASSIGNED Last reconfirmed||2025-05-22 --- Comment #1 from Gaius Mulley --- Confirmed, thanks for the report.
