https://gcc.gnu.org/g:9104472b645f76a212af9f9c58378500f9ba937e

commit r15-7234-g9104472b645f76a212af9f9c58378500f9ba937e
Author: Harald Anlauf <anl...@gmx.de>
Date:   Sun Jan 26 22:56:57 2025 +0100

    Fortran: fix bogus diagnostics on renamed interface import [PR110993]
    
            PR fortran/110993
    
    gcc/fortran/ChangeLog:
    
            * frontend-passes.cc (check_externals_procedure): Do not compare
            interfaces of a non-bind(C) procedure against a bind(C) global one.
            (check_against_globals): Use local name from rename-on-use in the
            search for interfaces.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/use_rename_14.f90: New test.

Diff:
---
 gcc/fortran/frontend-passes.cc              |  7 +++++
 gcc/testsuite/gfortran.dg/use_rename_14.f90 | 46 +++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/gcc/fortran/frontend-passes.cc b/gcc/fortran/frontend-passes.cc
index 987238794dab..6b470b83e21a 100644
--- a/gcc/fortran/frontend-passes.cc
+++ b/gcc/fortran/frontend-passes.cc
@@ -5704,6 +5704,9 @@ check_externals_procedure (gfc_symbol *sym, locus *loc,
   if (gsym->ns)
     gfc_find_symbol (sym->name, gsym->ns, 0, &def_sym);
 
+  if (gsym->bind_c && def_sym && def_sym->binding_label == NULL)
+    return 0;
+
   if (def_sym)
     {
       gfc_compare_actual_formal (&actual, def_sym->formal, 0, 0, 0, loc);
@@ -5800,6 +5803,10 @@ check_against_globals (gfc_symbol *sym)
 
   if (sym->binding_label)
     sym_name = sym->binding_label;
+  else if (sym->attr.use_rename
+          && sym->ns->use_stmts->rename
+          && sym->ns->use_stmts->rename->local_name[0] != '\0')
+    sym_name = sym->ns->use_stmts->rename->local_name;
   else
     sym_name = sym->name;
 
diff --git a/gcc/testsuite/gfortran.dg/use_rename_14.f90 
b/gcc/testsuite/gfortran.dg/use_rename_14.f90
new file mode 100644
index 000000000000..03815a5f229e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/use_rename_14.f90
@@ -0,0 +1,46 @@
+! { dg-do compile }
+!
+! PR fortran/110993 - bogus diagnostics on renamed interface import
+!
+! Contributed by Rimvydas Jasinskas <rimvydas.jas at gmail.com>
+
+module m
+  interface
+    subroutine bar(x)
+      use iso_c_binding, only : c_float
+      implicit none
+      real(c_float) :: x(45)
+    end subroutine
+  end interface
+end
+
+module m1
+  interface
+    subroutine bar1(x) bind(c)
+      use iso_c_binding, only : c_float
+      implicit none
+      real(c_float) :: x(45)
+    end subroutine
+  end interface
+end
+
+module m2
+  interface
+    subroutine bar2(x) bind(c, name="bar2_")
+      use iso_c_binding, only : c_float
+      implicit none
+      real(c_float) :: x(45)
+    end subroutine
+  end interface
+end
+
+subroutine foo(y)
+  use m,  notthisone => bar
+  use m1, northisone => bar1
+  use m2,  orthisone => bar2
+  implicit none
+  real :: y(3)
+  call bar (y)
+  call bar1(y)
+  call bar2(y)
+end subroutine

Reply via email to