[gcc r16-8491] Fortran: Fix ICE instantiating nested PDTs [PR124598]
Paul Thomas
pault@gcc.gnu.org
Tue Apr 7 06:42:31 GMT 2026
https://gcc.gnu.org/g:915d3e384e21fc57833463d3c2a08dcf6ff24788
commit r16-8491-g915d3e384e21fc57833463d3c2a08dcf6ff24788
Author: Paul Thomas <pault@gcc.gnu.org>
Date: Mon Apr 6 15:02:15 2026 +0100
Fortran: Fix ICE instantiating nested PDTs [PR124598]
2026-04-07 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/124598
* trans-expr.cc (gfc_conv_structure): Do not add parameterized
components to a structure constructor.
gcc/testsuite/
PR fortran/124598
* gfortran.dg/pdt_91.f03: New test.
Diff:
---
gcc/fortran/trans-expr.cc | 4 +++-
gcc/testsuite/gfortran.dg/pdt_91.f03 | 30 ++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index f50ddce8e829..6c0bd5ce9107 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -10528,7 +10528,9 @@ gfc_conv_structure (gfc_se * se, gfc_expr * expr, int init)
components. Although the latter have a default initializer
of EXPR_NULL,... by default, the static nullify is not needed
since this is done every time we come into scope. */
- if (!c->expr || (cm->attr.allocatable && cm->attr.flavor != FL_PROCEDURE))
+ if (!c->expr
+ || (cm->attr.allocatable && cm->attr.flavor != FL_PROCEDURE)
+ || (IS_PDT (cm) && has_parameterized_comps (cm->ts.u.derived)))
continue;
if (cm->initializer && cm->initializer->expr_type != EXPR_NULL
diff --git a/gcc/testsuite/gfortran.dg/pdt_91.f03 b/gcc/testsuite/gfortran.dg/pdt_91.f03
new file mode 100644
index 000000000000..ca0a79130ed2
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pdt_91.f03
@@ -0,0 +1,30 @@
+! {dg-do compile }
+! { dg-options "-fdump-tree-original" }
+!
+! Test the fix for PR124598.
+!
+! Contributed by Antoine Lemoine <antoine.lemoine@bordeaux-inp.fr>
+!
+program test_pdt
+ implicit none
+
+ type t_foo
+ integer :: c
+ end type t_foo
+
+ type t_bar(n)
+ integer, len :: n = 1
+ type(t_foo) :: foo(n)
+ end type t_bar
+
+ type t_baz(n)
+ integer, len :: n = 1
+ type(t_bar(n)) :: bar(n)
+ end type t_baz
+
+ type(t_baz(n=10)) :: baz ! Used to ICE at this line
+! baz%bar(1)%foo = t_foo(1)
+ print *, baz%bar(1)%foo
+end program test_pdt
+! Check that the upper bound for baz%bar%foo is set correctly.
+! { dg-final { scan-tree-dump-times "foo.dim.0..ubound = 10" 1 "original" } }
More information about the Gcc-cvs
mailing list