[gcc(refs/users/meissner/heads/work239-submit)] Fortran: Fix regression due to r16-669 [PR124161]

Michael Meissner meissner@gcc.gnu.org
Thu Mar 19 22:46:51 GMT 2026


https://gcc.gnu.org/g:74a3fcfa082efbf9ff4bf5b8f13fbeb564458682

commit 74a3fcfa082efbf9ff4bf5b8f13fbeb564458682
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Thu Mar 19 11:37:40 2026 +0000

    Fortran: Fix regression due to r16-669 [PR124161]
    
    2026-03-19  Paul Thomas  <pault@gcc.gnu.org>
    
    gcc/fortran
            PR fortran/124161
            * resolve.cc (resolve_symbol): Do not apply the default
            initializer if the symbol is used in a submodule.
    
    gcc/testsuite/
            PR fortran/124161
            * gfortran.dg/pr124161.f90: New test.

Diff:
---
 gcc/fortran/resolve.cc                 |  4 +--
 gcc/testsuite/gfortran.dg/pr124161.f90 | 61 ++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index e0cdd06cfde2..767bbdea1140 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -18913,8 +18913,8 @@ skip_interfaces:
 	  || (a->dummy && !a->pointer && a->intent == INTENT_OUT
 	      && sym->ns->proc_name->attr.if_source != IFSRC_IFBODY))
 	apply_default_init (sym);
-      else if (a->function && !a->pointer && !a->allocatable && !a->use_assoc
-	       && sym->result)
+      else if (a->function && !a->pointer && !a->allocatable
+	       && !a->use_assoc && !a->used_in_submodule && sym->result)
 	/* Default initialization for function results.  */
 	apply_default_init (sym->result);
       else if (a->function && sym->result && a->access != ACCESS_PRIVATE
diff --git a/gcc/testsuite/gfortran.dg/pr124161.f90 b/gcc/testsuite/gfortran.dg/pr124161.f90
new file mode 100644
index 000000000000..83a9545f92aa
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr124161.f90
@@ -0,0 +1,61 @@
+! { dg-do compile }
+!
+! Test the fix for the regression caused by r16-669-gd31ab498b12ebb - See line 59.
+!
+! Contributed by Zaak Beekman  <zbeekman@gmail.com>
+!
+module inner_m
+    implicit none
+    type :: dt_t
+        integer, allocatable :: val
+    end type
+    type, abstract :: inner_t
+    contains
+        procedure(summary_i), deferred :: summary
+    end type
+    abstract interface
+        function summary_i(self)
+            import :: inner_t, dt_t
+            class(inner_t), intent(in) :: self
+            type(dt_t) :: summary_i
+        end function
+    end interface
+end module inner_m
+
+module concrete_m
+    use inner_m, only: inner_t, dt_t
+    implicit none
+    type, extends(inner_t) :: concrete_t
+    contains
+        procedure :: summary
+    end type
+contains
+    function summary(self)
+        class(concrete_t), intent(in) :: self
+        type(dt_t) :: summary
+    end function
+end module concrete_m
+
+module outer_m
+    use inner_m, only: inner_t, dt_t
+    use concrete_m, only: concrete_t
+    implicit none
+    type :: outer_t
+        class(inner_t), allocatable :: component
+    contains
+        procedure :: summary
+    end type
+    interface
+        module function summary(self) result(res)
+            class(outer_t), intent(in) :: self
+            type(dt_t) :: res
+        end function
+    end interface
+end module outer_m
+
+submodule(outer_m) outer_impl
+contains
+    module procedure summary
+        res = self%component%summary()  ! ICE in trans_scalar_assign here
+    end procedure
+end submodule outer_impl


More information about the Gcc-cvs mailing list