https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95542
--- 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:47ec169c00cd1da6a9b0cecf871ccfb2a26fd63c commit r17-3339-g47ec169c00cd1da6a9b0cecf871ccfb2a26fd63c Author: Jerry DeLisle <[email protected]> Date: Sun Jul 12 15:25:18 2026 -0700 fortran: [PR95542] Fix ICE for deferred-length CHARACTER result via host association gfc_get_symbol_decl has an assert meant to verify that a deferred-length string's length variable lives in the same scope as the symbol it belongs to. This is wrong when sym->backend_decl is itself the enclosing function's FUNCTION_DECL. The correct comparison is DECL_CONTEXT (length) == sym->backend_decl directly. This was hit when a deferred-length CHARACTER function's own result was assigned to or read from a CONTAINED subprocedure via host association. PR fortran/95542 gcc/fortran/ChangeLog: * trans-decl.cc (gfc_get_symbol_decl): When checking that a deferred-length string's length variable shares the symbol's scope, special-case sym->backend_decl being a FUNCTION_DECL (an implicit function-result variable): compare against sym->backend_decl directly instead of its own DECL_CONTEXT. gcc/testsuite/ChangeLog: * gfortran.dg/pr95542.f90: New test.
