https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119118
--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Harald Anlauf <anl...@gcc.gnu.org>: https://gcc.gnu.org/g:ac8a70db59ac309daf866a65b5785e472e76d406 commit r15-7873-gac8a70db59ac309daf866a65b5785e472e76d406 Author: Harald Anlauf <anl...@gmx.de> Date: Thu Mar 6 21:45:42 2025 +0100 Fortran: improve checking of substring bounds [PR119118] After the fix for pr98490 no substring bounds check was generated if the substring start was not a variable. While the purpose of that fix was to suppress a premature check before implied-do indices were substituted, this prevented a check if the substring start was an expression or a constant. A better solution is to defer the check until implied-do indices have been substituted in the start and end expressions. PR fortran/119118 gcc/fortran/ChangeLog: * dependency.cc (gfc_contains_implied_index_p): Helper function to determine if an expression has a dependence on an implied-do index. * dependency.h (gfc_contains_implied_index_p): Add prototype. * trans-expr.cc (gfc_conv_substring): Adjust logic to not generate substring bounds checks before implied-do indices have been substituted. gcc/testsuite/ChangeLog: * gfortran.dg/bounds_check_23.f90: Generalize test. * gfortran.dg/bounds_check_26.f90: New test.