https://gcc.gnu.org/g:1cd19b54fbfedfd1ac49409fa67f20ed84e0e88b
commit r16-9112-g1cd19b54fbfedfd1ac49409fa67f20ed84e0e88b Author: Paul Thomas <[email protected]> Date: Sun Jun 7 09:11:13 2026 +0100 Fortran: Fix regression caused by first patch [PR125527] 2026-06-07 Paul Thomas <[email protected]> gcc/fortran PR fortran/125527 * class.cc (gfc_find_derived_vtab): Stash module namespace and use it as the last place to search for the vtab before building a new one. (cherry picked from commit 62b2b65c59d3f26e090ae74879df379163fda407) Diff: --- gcc/fortran/class.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gcc/fortran/class.cc b/gcc/fortran/class.cc index 2a7b42f6a457..956572f7de1a 100644 --- a/gcc/fortran/class.cc +++ b/gcc/fortran/class.cc @@ -2491,6 +2491,7 @@ gfc_find_derived_vtab (gfc_symbol *derived) /* Work in the gsymbol namespace if the top-level namespace is a module. This ensures that the vtable is unique, which is required since we use its address in SELECT TYPE. */ + gfc_namespace *module_ns = ns; if (gsym && gsym->ns && ns && ns->proc_name && ns->proc_name->attr.flavor == FL_MODULE) ns = gsym->ns; @@ -2516,6 +2517,11 @@ gfc_find_derived_vtab (gfc_symbol *derived) gfc_find_symbol (name, ns, 0, &vtab); if (vtab == NULL) gfc_find_symbol (name, derived->ns, 0, &vtab); + /* If all else fails, look in the module/submodule namespace so that + the module variable and procedure body translations find the same + frontend symbol and backend decl. */ + if (vtab == NULL && module_ns != ns) + gfc_find_symbol (name, module_ns, 0, &vtab); if (vtab == NULL) { @@ -3136,9 +3142,7 @@ find_typebound_proc_uop (gfc_symbol* derived, bool* t, root = (uop ? derived->f2k_derived->tb_uop_root : derived->f2k_derived->tb_sym_root); else - /* No f2k_derived namespace; allow the extension check below to proceed - so inherited type-bound procedures/operators are still found. */ - root = NULL; + return NULL; /* Try to find it in the current type's namespace. */ res = gfc_find_symtree (root, name);
