https://gcc.gnu.org/g:aff1672005353f1be41e6cc2423bf0647e2222bc
commit r16-9260-gaff1672005353f1be41e6cc2423bf0647e2222bc Author: Jerry DeLisle <[email protected]> Date: Sat Jul 11 10:35:29 2026 -0700 fortran: [PR126210] Restrict host-assoc symbol skip to derived types The fix for PR126170 made read_module() skip re-importing any symbol already visible via host association from the same module, matched only by name. PR fortran/126210 gcc/fortran/ChangeLog: * module.cc (read_module): Only skip re-importing a symbol already visible via host association from the same module when that symbol is a derived type. gcc/testsuite/ChangeLog: * gfortran.dg/pr126210.f90: New test. (cherry picked from commit 69a2daacba6353d1aab3118415b89afd479c4c76) Diff: --- gcc/fortran/module.cc | 7 ++++--- gcc/testsuite/gfortran.dg/pr126210.f90 | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/gcc/fortran/module.cc b/gcc/fortran/module.cc index 4600845f5f6d..7206048c407f 100644 --- a/gcc/fortran/module.cc +++ b/gcc/fortran/module.cc @@ -5881,15 +5881,16 @@ read_module (void) module_name, 0)) continue; - /* Skip re-importing a symbol already visible via host association - from the same module. */ + /* Skip re-importing a derived type already visible via host + association from the same module. */ if (!only_flag && !info->u.rsym.renamed && strcmp (name, module_name) != 0 && gfc_current_ns->parent) { gfc_symbol *host_sym; gfc_find_symbol (name, gfc_current_ns, 1, &host_sym); - if (host_sym && host_sym->module + if (host_sym && host_sym->attr.flavor == FL_DERIVED + && host_sym->module && strcmp (host_sym->module, module_name) == 0) continue; } diff --git a/gcc/testsuite/gfortran.dg/pr126210.f90 b/gcc/testsuite/gfortran.dg/pr126210.f90 new file mode 100644 index 000000000000..64f45be317a0 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr126210.f90 @@ -0,0 +1,26 @@ +! { dg-do compile } +! +! PR fortran/126210 +! A redundant, already host-associated USE inside a contained +! subroutine of a module defining an interface whose specific procedure +! shares the generic's name caused a mismatch error. + +module amod + interface foo + function foo (x) bind (c) + use iso_c_binding, only : c_int + integer (c_int) :: foo + integer (c_int), value :: x + end function foo + end interface +end module amod + +module m + use amod +contains + subroutine bar (y) + use amod + integer :: y + y = foo (1) + end subroutine bar +end module m
