https://gcc.gnu.org/g:69a2daacba6353d1aab3118415b89afd479c4c76

commit r17-2332-g69a2daacba6353d1aab3118415b89afd479c4c76
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.

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 f7bf5854d745..e098bd17725f 100644
--- a/gcc/fortran/module.cc
+++ b/gcc/fortran/module.cc
@@ -6053,15 +6053,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

Reply via email to