https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125763
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jerry DeLisle <[email protected]>: https://gcc.gnu.org/g:3461bb8b7148d0cfe1a1505768accef330e88743 commit r17-5521-g3461bb8b7148d0cfe1a1505768accef330e88743 Author: Jerry DeLisle <[email protected]> Date: Fri Oct 23 14:26:45 2026 -0400 fortran: [PR125763] Fix ICE for character pointer initialized to a substring A character pointer initialized to a substring in its declaration, e.g. character(len=:), pointer :: p => t(2:4) ICE'd in gfc_get_symbol_decl because the substring's character length was never set. gfc_resolve_expr did not resolve the substring length when the first reference of the variable is the substring itself, as for a scalar variable, so fixup_charlen gave the expression a charlen with no length. Resolve the substring length in that case too. With that change, the frontend temporary that create_var makes for a deferred-length assignment such as a = a(m:n) gets an explicit LEN() length but kept the deferred flag of the variable, which tripped an assertion in gfc_trans_deferred_vars. Clear the deferred flag when the temporary is given an explicit length. PR fortran/125763 gcc/fortran/ChangeLog: * frontend-passes.cc (create_var): Clear ts.deferred when the temporary gets an explicit length from LEN(). * resolve.cc (gfc_resolve_expr): Resolve the substring length also when the first reference is the substring. gcc/testsuite/ChangeLog: * gfortran.dg/char_pointer_substring_init.f90: New test.
