https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120389
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Gaius Mulley <ga...@gcc.gnu.org>: https://gcc.gnu.org/g:e131ba3de5f487f5e957ba1b011c960fce557c7b commit r16-1026-ge131ba3de5f487f5e957ba1b011c960fce557c7b Author: Gaius Mulley <gaiusm...@gmail.com> 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/pim/pass/testxindr2.mod: New test. * gm2/pim/pass/testxindr3.mod: New test. Signed-off-by: Gaius Mulley <gaiusm...@gmail.com>