The following fix provided by Steve.
Fairly self explanatory.
Regression tested x86_64-linux.
OK for mainline? Copied release manager as we are in Stage 4.
Regards,
Jerry
Author: Steven G. Kargl <[email protected]>
Date: Fri Jan 16 14:05:16 2026 -0800
Fortran: Fix accepts invalid implicit none (external)
This patch yields an error for the test case which was
previously being accepted even though implicit none (external)
was being specified.
PR fortran/109512
gcc/fortran/ChangeLog:
* resolve.cc (resolve_call): Check if an external attribute is
required on a call to an external function.
gcc/testsuite/ChangeLog:
* gfortran.dg/pr109512.f90: New test.
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index be72132c79d..dfc2803a7c8 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -4167,6 +4167,16 @@ resolve_call (gfc_code *c)
/* Resume assumed_size checking. */
need_full_assumed_size--;
+ /* If 'implicit none (external)' and the symbol is a dummy argument,
+ check for an 'external' attribute. */
+ if (csym->ns->has_implicit_none_export
+ && csym->attr.external == 0 && csym->attr.dummy == 1)
+ {
+ gfc_error ("Dummy procedure %qs at %L requires an EXTERNAL attribute",
+ csym->name, &c->loc);
+ return false;
+ }
+
/* If external, check for usage. */
if (csym && is_external_proc (csym))
resolve_global_procedure (csym, &c->loc, 1);
diff --git a/gcc/testsuite/gfortran.dg/pr109512.f90
b/gcc/testsuite/gfortran.dg/pr109512.f90
new file mode 100644
index 00000000000..f2b4cd53003
-- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr109512.f90
@@ -0,0 +1,5 @@
+! { dg-do compile }
+subroutine foo(bar)
+ implicit none (external)
+ call bar(1) ! { dg-error "requires an EXTERNAL attribute" }
+end subroutine foo