Dear all,

my original patch caused a regression on previously working code where
an imported interface was *not* renamed-on-use, as the related new logic
did not expect a local_name to be an empty string.

Funnily, there was no previously existing test in the testsuite...

The attached fixes this and regtests fine on x86_64-pc-linux-gnu.

OK for mainline and affected branch(es)?

Thanks,
Harald

From f5589149d5ae434c4c68c77ef0b5dd912da574df Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anl...@gmx.de>
Date: Fri, 27 Jun 2025 22:37:41 +0200
Subject: [PATCH] Fortran: follow-up fix to checking of renamed-on-use
 interface name [PR120784]

Commit r16-1633 introduced a regression for imported interfaces that were
not renamed-on-use, since the related logic did not take into account that
the absence of renaming could be represented by an empty string.

gcc/fortran/ChangeLog:

	* interface.cc (gfc_match_end_interface): Detect empty local_name.

gcc/testsuite/ChangeLog:

	* gfortran.dg/interface_63.f90: Extend testcase.
---
 gcc/fortran/interface.cc                   |  4 ++-
 gcc/testsuite/gfortran.dg/interface_63.f90 | 35 ++++++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc
index cdb838d8336..f74fbf0f6e5 100644
--- a/gcc/fortran/interface.cc
+++ b/gcc/fortran/interface.cc
@@ -457,7 +457,9 @@ gfc_match_end_interface (void)
 
       if (current_interface.sym->attr.use_assoc
 	  && current_interface.sym->attr.use_rename
-	  && current_interface.sym->ns->use_stmts->rename)
+	  && current_interface.sym->ns->use_stmts->rename
+	  && (current_interface.sym->ns->use_stmts->rename->local_name[0]
+	      != '\0'))
 	local_name = current_interface.sym->ns->use_stmts->rename->local_name;
 
       if (type != current_interface.type
diff --git a/gcc/testsuite/gfortran.dg/interface_63.f90 b/gcc/testsuite/gfortran.dg/interface_63.f90
index a55e8ab431b..56c1644ed82 100644
--- a/gcc/testsuite/gfortran.dg/interface_63.f90
+++ b/gcc/testsuite/gfortran.dg/interface_63.f90
@@ -60,3 +60,38 @@ program p
   call myget (i)
   call myget (r)
 end
+
+! Check that we do not regress on the following:
+
+module mod1
+  implicit none
+
+  interface local
+    module procedure local_data
+  end interface local
+
+contains
+
+  logical function local_data (data) result (local)
+    real, intent(in) :: data
+    local = .true.
+  end function local_data
+
+end module mod1
+
+module mod2
+  use mod1, only: local
+  implicit none
+
+  interface local
+     module procedure local_invt
+  end interface local
+
+contains
+
+  logical function local_invt (invt) result (local)
+    integer, intent(in) :: invt
+    local = .true.
+  end function local_invt
+
+end module mod2
-- 
2.43.0

Reply via email to