https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120389
--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-15 branch has been updated by Gaius Mulley <ga...@gcc.gnu.org>: https://gcc.gnu.org/g:1e9255f7b35973686ea6e091d340259edb3ac4b1 commit r15-9984-g1e9255f7b35973686ea6e091d340259edb3ac4b1 Author: Gaius Mulley <gaiusm...@gmail.com> 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. * gm2/pim/pass/testxindr3.mod: New test. (cherry picked from commit e131ba3de5f487f5e957ba1b011c960fce557c7b) Signed-off-by: Gaius Mulley <gaiusm...@gmail.com>