[gcc r17-2763] fortran: [PR125866] Fix ICE: a module procedure with an allocatable, intent(out)

Jerry DeLisle via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:2886a168e82e603f8141d5ea633a0eb0a4a58a6e

commit r17-2763-g2886a168e82e603f8141d5ea633a0eb0a4a58a6e
Author: Jerry DeLisle <[email protected]>
Date:   Tue Jul 28 12:53:30 2026 -0700

    fortran: [PR125866] Fix ICE: a module procedure with an allocatable, intent(out)
    
    Co-authored by: Steve Kargl <[email protected]>
    
            PR fortran/125866
    
    gcc/fortran/ChangeLog:
    
            * expr.cc (is_CFI_desc): Add check for proc_name.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/pr125866.f90: New test.

Diff:
---
 gcc/fortran/expr.cc                    |  2 +-
 gcc/testsuite/gfortran.dg/pr125866.f90 | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index 946fa86a8223..d0f07eec2d44 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -1193,7 +1193,7 @@ is_CFI_desc (gfc_symbol *sym, gfc_expr *e)
       && e && e->expr_type == EXPR_VARIABLE)
     sym = e->symtree->n.sym;
 
-  if (sym && sym->attr.dummy
+  if (sym && sym->attr.dummy && sym->ns && sym->ns->proc_name
       && sym->ns->proc_name->attr.is_bind_c
       && (sym->attr.pointer
 	  || sym->attr.allocatable
diff --git a/gcc/testsuite/gfortran.dg/pr125866.f90 b/gcc/testsuite/gfortran.dg/pr125866.f90
new file mode 100644
index 000000000000..e0bc7b746f69
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr125866.f90
@@ -0,0 +1,28 @@
+! { dg-do compile }
+!  ICE: a module procedure with an allocatable, intent(out)
+!  derived-type array dummy. Reduced from the original in the PR
+
+module m
+  interface
+    module subroutine s (a)
+      integer, allocatable, intent(out) :: a
+    end subroutine
+  end interface
+end module
+
+submodule (m) sm1
+contains
+  module subroutine s (a)
+    integer, allocatable, intent(out) :: a
+    allocate (a, source = 7)
+  end subroutine
+end submodule
+
+submodule (m:sm1) sm2
+contains
+  subroutine caller
+    integer, allocatable :: b
+    call s (b)
+    if (b /= 7) stop 1
+  end subroutine
+end submodule
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.