https://gcc.gnu.org/g:6be9db000810a44c5b6b5af320723b3af175bb8a
commit r16-8539-g6be9db000810a44c5b6b5af320723b3af175bb8a 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: --- gcc/fortran/resolve.cc | 25 +++++++++++++++---------- gcc/testsuite/gfortran.dg/pr96986.f90 | 25 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 9152e7f71463..eac6e81c2337 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 000000000000..56ee6717a9ae --- /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
