https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128316
--- Comment #7 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:7bbecd581aa6f87c68d9d1088ee97b1d7f96005a commit r17-6641-g7bbecd581aa6f87c68d9d1088ee97b1d7f96005a Author: Jerry DeLisle <[email protected]> Date: Sun Nov 15 13:13:52 2026 -0800 fortran: [PR128316] ICE for a labeled END statement after CONTAINS A label on the END statement of a program unit with a CONTAINS section caused an ICE when nothing branched to it, because the fix for PR126909 moved the label to the host without a source location. That code also found the host through the symbol of the enclosing state, which is null for an unnamed main program, so a GOTO to the label was rejected there; it skipped module procedures, and took the label number from the root of the label tree rather than from the END statement. Define the label in the parent of the scratch namespace that parse_contained opens, which is always the host, with gfc_define_st_label and the label and location of the statement. That also diagnoses a duplicate of a host label. The label of an END MODULE or END SUBMODULE statement after a CONTAINS section was dropped with the scratch namespace, so a duplicate of it was accepted; define it in the module. Assisted-by: Claude Opus 5.5 PR fortran/128316 gcc/fortran/ChangeLog: * parse.cc (accept_statement): For a labeled END statement after a CONTAINS section, define the label in the host namespace with its source location, for any host program unit. Likewise for END MODULE and END SUBMODULE. gcc/testsuite/ChangeLog: * gfortran.dg/label_6.f90: New test. * gfortran.dg/label_7.f90: New test. * gfortran.dg/label_8.f90: New test.
