https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126909
--- Comment #1 from Steve Kargl <kargl at gcc dot gnu.org> ---
A quick debugging session suggests that the label is
inserted into the conflicting namespaces.
(gdb) b match.cc:545
(gdb) run t2.f90
Breakpoint 1, gfc_match_st_label (label=0x7fffffffe0c8) at
../../gcc/gcc/fortran/match.cc:545
545 old_loc = gfc_current_locus;
(gdb) p gfc_state_stack->state
$4 = COMP_PROGRAM
This is the 'goto 10' statement, and we're in the COMP_PROGRAM
namespace
(gdb) c
Continuing.
Breakpoint 1, gfc_match_st_label (label=label@entry=0x37e7278
<gfc_statement_label>)
at ../../gcc/gcc/fortran/match.cc:545
545 old_loc = gfc_current_locus;
(gdb) p gfc_state_stack->state
$5 = COMP_CONTAINS
We're now in a 'contains' namespace.
(gdb) bt
#0 gfc_match_st_label (label=label@entry=0x37e7278 <gfc_statement_label>)
at ../../gcc/gcc/fortran/match.cc:545
#1 0x0000000000add4ca in next_free () at ../../gcc/gcc/fortran/parse.cc:1592
#2 next_statement () at ../../gcc/gcc/fortran/parse.cc:1931
#3 0x0000000000ae362f in parse_contained (module=module@entry=0)
at ../../gcc/gcc/fortran/parse.cc:7052
#4 0x0000000000ae3224 in parse_progunit (st=<optimized out>, st@entry=ST_NONE)
at ../../gcc/gcc/fortran/parse.cc:7286
#5 0x0000000000ae48e6 in gfc_parse_file () at
../../gcc/gcc/fortran/parse.cc:7799
#6 0x0000000000b4d298 in gfc_be_parse_file () at
../../gcc/gcc/fortran/f95-lang.cc:249
#7 0x00000000012b4b3a in compile_file () at ../../gcc/gcc/toplev.cc:455
#8 0x0000000000a075d4 in do_compile () at ../../gcc/gcc/toplev.cc:2228
#9 toplev::main (this=this@entry=0x7fffffffe60e, argc=<optimized out>,
argc@entry=2,
argv=<optimized out>, argv@entry=0x7fffffffe6a0) at
../../gcc/gcc/toplev.cc:2396
#10 0x0000000000a08efe in main (argc=2, argv=0x7fffffffe6a0) at
../../gcc/gcc/main.cc:39
After accepting the labeled end-program-stmt we have
(gdb) p *gfc_current_ns->st_labels
$16 = {priority = 23594, left = 0x0, right = 0x0, value = 10, defined =
ST_LABEL_TARGET,
referenced = ST_LABEL_UNKNOWN, format = 0x0, backend_decl = 0x0, where =
{nextc = 0x804612488, u = {lb = 0x804612460, location = 34433213536}}, ns =
0x804750c00, omp_region = 0}
(gdb) p *gfc_current_ns->parent->st_labels
$17 = {priority = 13545, left = 0x0, right = 0x0, value = 10, defined =
ST_LABEL_UNKNOWN,
referenced = ST_LABEL_TARGET, format = 0x0, backend_decl = 0x0, where =
{nextc = 0x8046de468, u = {lb = 0x8046de420, location = 34434049056}}, ns =
0x80474f400, omp_region = 0}