https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117371
--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-14 branch has been updated by Gaius Mulley <ga...@gcc.gnu.org>: https://gcc.gnu.org/g:c1409e1955110fcf3641cec6e8381fbf03f0a510 commit r14-11057-gc1409e1955110fcf3641cec6e8381fbf03f0a510 Author: Gaius Mulley <gaiusm...@gmail.com> Date: Wed Dec 4 00:11:22 2024 +0000 [PATCH] PR modula2/117371: type incompatibility between INTEGER and CARDINAL This patch enforces a const expression increment in a FOR loop. It also fixes missing error locations. The FOR loop last iterator value is now calculated during M2GenGCC after all types and constants have been resolved. This results in fewer quadruples (as there is no need to build two paths for step > 0 and step < 0). gcc/m2/ChangeLog: PR modula2/117371 * gm2-compiler/M2Base.mod (MixMetaTypes): Add parameter TRUE to MetaErrorDecl. (IsUserType): Test against ZType. (MixTypesDecl): Test for ZType. * gm2-compiler/M2GenGCC.mod (ErrorMessageDecl): Add parameter TRUE to MetaErrorDecl. (CodeLastForIterator): New procedure. (FoldLastForIterator): Ditto. (PerformLastForIterator): Ditto. (CodeStatement): Add case clause for LastForIteratorOp. (ErrorMessageDecl): Add iserror parameter. Call MetaErrorDecl with iserror parameter. (checkIncorrectMeta): Call MetaErrorDecl with TRUE parameter. (CheckBinaryExpressionTypes): Ditto. (CheckElementSetTypes): Ditto. * gm2-compiler/M2LexBuf.def (MakeVirtualTok): Update comment detailing the fall back when UnknownTokenNo is encountered. (MakeVirtual2Tok): Ditto. * gm2-compiler/M2LexBuf.mod (MakeVirtualTok): Check against UnknownTokenNo. (MakeVirtual2Tok): Ditto. * gm2-compiler/M2MetaError.def (MetaErrorDecl): Add error parameter. * gm2-compiler/M2MetaError.mod (MetaErrorDecl): Add error parameter. Issue warning if error is FALSE. * gm2-compiler/M2Quads.def (QuadOperator): Add LastForIteratorOp. * gm2-compiler/M2Quads.mod (AddQuadInformation): New case clause LastForIteratorOp. (CheckAddTuple2Read): New procedure. (BuildForLoopToRangeCheck): Remove. (ForLoopLastIteratorVariable): Ditto. (ForLoopLastIteratorConstant): Ditto. (ForLoopLastIterator): Reimplement. (BuildForToByDo): Remove ByType from call to ForLoopLastIterator. (WriteQuad): New case clause LastForIteratorOp. (WriteOperator): Ditto. * gm2-compiler/M2Students.def (CheckForVariableThatLooksLikeKeyword): Replace with ... (CheckVariableAgainstKeyword): ... this. * gm2-compiler/M2Students.mod (CheckForVariableThatLooksLikeKeyword): Replace with ... (CheckVariableAgainstKeyword): ... this. * gm2-compiler/M2SymInit.mod (CheckLastForIterator): New procedure. (CheckReadBeforeInitQuad): New case clause to call CheckLastForIterator. * gm2-compiler/P2SymBuild.mod: Replace CheckForVariableThatLooksLikeKeyword with CheckVariableAgainstKeyword. gcc/testsuite/ChangeLog: PR modula2/117371 * gm2/iso/fail/forloopbyvar.mod: New test. * gm2/iso/fail/forloopbyvar4.mod: New test. * gm2/iso/fail/forloopbyvar5.mod: New test. * gm2/iso/pass/forloopbyvar3.mod: New test. (cherry picked from commit f242f79b8afeec58477e99c44530bd503878c6d5) Signed-off-by: Gaius Mulley <gaiusm...@gmail.com>