Le 15/11/2026 à 22:19, Jerry DeLisle a écrit :
See attached patch. A label on the END statement of a program unit with
a CONTAINS section caused an ICE in gfc_get_location_with_offset when
nothing branched to it. This is a mainline regression from the PR126909
fix (34762afa322), which moves such a label from the scratch namespace
that parse_contained opens to the host, but created the host label
without a source location. The same code missed the host of an unnamed
main program and of a module procedure, and could take the wrong label
number. The patch defines the label in the parent of the scratch
namespace, which is always the host, with gfc_define_st_label and the
label and location of the statement; that also reports a duplicate of
a host label.
The fix is in accept_statement in parse.cc; the rest is the two new
tests.
Regression tested on x86_64.
OK for mainline?
OK.
The sashiko review [1] suggests that a duplicate statement label in a
module or submodule is not diagnosed. Sounds convincing, but probably
worth a separate PR.
[1]:
https://gcc.sashiko.dev/#/patchset/20261115211908.597643-1-jvdelisle2%40gmail.com
Regards,
Jerry
---
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.
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.
gcc/testsuite/ChangeLog:
* gfortran.dg/label_6.f90: New test.
* gfortran.dg/label_7.f90: New test.