The attached patch avoids a bogus error given on valid code.
Regression tested on x86_64.
I plan to commit this one sometime tomorrow.
Regards,
Jerry
---
Author: Christopher Albert <[email protected]>
Date: Sun Mar 29 21:52:37 2026 +0200
fortran: Fix false explicit-interface-required for ENTRY with volatile
[PR96986]
When resolving a call to an ENTRY procedure, the entry lookup that
replaces the master procedure's def_sym with the specific entry symbol
was inside the 'resolved != -1' block. During recursive resolution the
namespace is marked resolved == -1, so the lookup was skipped and the
explicit interface check used the master procedure's combined formal
argument list instead of the entry's own formals.
Move the entry lookup after the resolution block so it runs regardless
of the namespace resolution state.
PR fortran/96986
gcc/fortran/ChangeLog:
* resolve.cc (resolve_global_procedure): Move entry symbol
lookup outside the resolved != -1 block.
gcc/testsuite/ChangeLog:
* gfortran.dg/pr96986.f90: New test.
Signed-off-by: Christopher Albert <[email protected]>
commit 7d0ee2cfe3f46f272fd2c4632c6ff85f66235399
Author: Christopher Albert <[email protected]>
Date: Sun Mar 29 21:52:37 2026 +0200
fortran: Fix false explicit-interface-required for ENTRY with volatile [PR96986]
When resolving a call to an ENTRY procedure, the entry lookup that
replaces the master procedure's def_sym with the specific entry symbol
was inside the 'resolved != -1' block. During recursive resolution the
namespace is marked resolved == -1, so the lookup was skipped and the
explicit interface check used the master procedure's combined formal
argument list instead of the entry's own formals.
Move the entry lookup after the resolution block so it runs regardless
of the namespace resolution state.
PR fortran/96986
gcc/fortran/ChangeLog:
* resolve.cc (resolve_global_procedure): Move entry symbol
lookup outside the resolved != -1 block.
gcc/testsuite/ChangeLog:
* gfortran.dg/pr96986.f90: New test.
Signed-off-by: Christopher Albert <[email protected]>
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 9152e7f7146..eac6e81c233 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -2787,17 +2787,22 @@ resolve_global_procedure (gfc_symbol *sym, locus *where, int sub)
/* This can happen if a binding name has been specified. */
if (gsym->binding_label && gsym->sym_name != def_sym->name)
gfc_find_symbol (gsym->sym_name, gsym->ns, 0, &def_sym);
+ }
- if (def_sym->attr.entry_master || def_sym->attr.entry)
- {
- gfc_entry_list *entry;
- for (entry = gsym->ns->entries; entry; entry = entry->next)
- if (strcmp (entry->sym->name, sym->name) == 0)
- {
- def_sym = entry->sym;
- break;
- }
- }
+ /* Look up the specific entry symbol so that interface checks use
+ the entry's own formal argument list, not the entry master's.
+ This must run even when resolved == -1 (recursive resolution in
+ progress), because def_sym starts as the namespace proc_name
+ which is the entry master with the combined formals. */
+ if (def_sym->attr.entry_master || def_sym->attr.entry)
+ {
+ gfc_entry_list *entry;
+ for (entry = gsym->ns->entries; entry; entry = entry->next)
+ if (strcmp (entry->sym->name, sym->name) == 0)
+ {
+ def_sym = entry->sym;
+ break;
+ }
}
if (sym->attr.function && !gfc_compare_types (&sym->ts, &def_sym->ts))
diff --git a/gcc/testsuite/gfortran.dg/pr96986.f90 b/gcc/testsuite/gfortran.dg/pr96986.f90
new file mode 100644
index 00000000000..56ee6717a9a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr96986.f90
@@ -0,0 +1,25 @@
+! { dg-do compile }
+! { dg-options "-std=legacy" }
+!
+! PR fortran/96986
+! Calling an ENTRY with no volatile arguments incorrectly required an
+! explicit interface because the volatile attribute from a sibling ENTRY
+! was checked against the master procedure's combined formal list.
+
+subroutine volatile_test ()
+ implicit none
+ integer, volatile :: va
+
+ entry fun_a()
+ return
+
+ entry fun_b(va)
+ call fun_c()
+ return
+end subroutine volatile_test
+
+subroutine fun_c ()
+ implicit none
+ call fun_a() ! Must not require explicit interface
+ return
+end subroutine fun_c