]> git.ipfire.org Git - thirdparty/gcc.git/commit
fortran: Favor parser-generated module procedure namespaces [PR122046]
authorMikael Morin <morin-mikael@orange.fr>
Wed, 24 Sep 2025 14:06:59 +0000 (16:06 +0200)
committerMikael Morin <mikael@gcc.gnu.org>
Wed, 24 Sep 2025 19:02:48 +0000 (21:02 +0200)
commit33862166186fcef86e94babded780bb3745f6525
treeff9a3158a5751a1e67bdec40813a8f7a2fa75c7f
parent966cdec2b23b8049c263e2239a3da38937ae01d2
fortran: Favor parser-generated module procedure namespaces [PR122046]

In the testcase from the PR, an assertion triggers because the compiler
tries to access the parent namespace of a contained procedure.  But the
namespace is the formal namespace of a module procedure symbol in a
submodule, which hasn't its parent set.

To add a bit of context, in submodules, module procedures inherited from
their parent module have two different namespaces holding their dummy
arguments.  The first one is generated by the the host association of
the module from the .mod file, and is made accessible in the procedure
symbol's formal_ns field.  Its parent field is not set.  The second one
is generated by the parser and contains the procedure implementation.
It's accessible from the list of contained procedures in the submodule
namespace.  Its parent field is set.

This change modifies gfc_get_procedure_ns to favor the parser-generated
namespace in the submodule case where there are two namespaces to choose
from.

PR fortran/122046

gcc/fortran/ChangeLog:

* symbol.cc (gfc_get_procedure_ns): Try to find the namespace
among the list of contained namespaces before returning the
value from the formal_ns field.

gcc/testsuite/ChangeLog:

* gfortran.dg/submodule_34.f90: New test.
gcc/fortran/symbol.cc
gcc/testsuite/gfortran.dg/submodule_34.f90 [new file with mode: 0644]