Hello All,

The attached patch fixes PR121204 and passes regression testing on FC44/x86_64.

I was working in the right place but completely missed the lack of the
always_explicit attribute. claude found it right away.

The patch passes regetesting on FC44/x86_64.

As it is a trivial one liner, I intend to push it in the next hour or
so and to backport with a sensible delay.

Regards

Paul
From 3b2d9f162a07e9d7b6b4a8b4acacf080ce89f9b6 Mon Sep 17 00:00:00 2001
From: Paul Thomas <[email protected]>
Date: Thu, 4 Jun 2026 11:55:50 +0100
Subject: [PATCH] Fortran: fix always_explicit not copied by gfc_copy_attr
 [PR119882]

gfc_copy_attr omitted the always_explicit attribute, so when
gfc_copy_dummy_sym created a fresh copy of a dummy procedure symbol in
a submodule module procedure (gfc_match_submod_proc), the flag was
silently lost.  At translation time nodesc_arg was set true for calls
through that dummy procedure, causing array constructors to be passed
as raw data pointers instead of array descriptors.  Callers with
assumed-shape dummy arguments then read garbage bounds.

gcc/fortran/ChangeLog:

	* symbol.cc (gfc_copy_attr): Copy the always_explicit attribute.

gcc/testsuite/ChangeLog:

	* gfortran.dg/submodule_36.f90: New test.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
---
 gcc/fortran/symbol.cc                      |  2 ++
 gcc/testsuite/gfortran.dg/submodule_36.f90 | 38 ++++++++++++++++++++++
 2 files changed, 40 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/submodule_36.f90

diff --git a/gcc/fortran/symbol.cc b/gcc/fortran/symbol.cc
index 26e4b40d48e..d2e93755c53 100644
--- a/gcc/fortran/symbol.cc
+++ b/gcc/fortran/symbol.cc
@@ -2224,6 +2224,8 @@ gfc_copy_attr (symbol_attribute *dest, symbol_attribute *src, locus *where)
     goto fail;
   if (src->recursive && !gfc_add_recursive (dest, where))
     goto fail;
+  if (src->always_explicit)
+    dest->always_explicit = 1;
 
   if (src->flavor != FL_UNKNOWN
       && !gfc_add_flavor (dest, src->flavor, NULL, where))
diff --git a/gcc/testsuite/gfortran.dg/submodule_36.f90 b/gcc/testsuite/gfortran.dg/submodule_36.f90
new file mode 100644
index 00000000000..ac80e2bddda
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/submodule_36.f90
@@ -0,0 +1,38 @@
+! { dg-do run }
+!
+! Test fix for a bug where the always_explicit attribute was not copied
+! by gfc_copy_attr, causing array descriptors not to be passed when
+! calling a dummy procedure with an assumed-shape argument from a
+! submodule module procedure.
+!
+module test_m
+   implicit none (type, external)
+   interface
+      module subroutine call_proc (proc)
+         interface
+            subroutine proc (a)
+               real, intent(in) :: a(:)
+            end subroutine proc
+         end interface
+      end subroutine call_proc
+   end interface
+end module test_m
+
+submodule (test_m) test_sm
+   implicit none (type, external)
+contains
+   module procedure call_proc
+      call proc ([1., 2., .3])
+   end procedure call_proc
+end submodule test_sm
+
+program test
+   use test_m
+   implicit none (type, external)
+   call call_proc (print_proc)
+contains
+   subroutine print_proc (a)
+      real, intent(in) :: a(:)
+      if (size (a, 1) /= 3) stop 1
+   end subroutine print_proc
+end program test
-- 
2.54.0

Reply via email to