https://gcc.gnu.org/g:f229fd09f6cecdb4f4286d1eba7d349775518cd7
commit r17-5109-gf229fd09f6cecdb4f4286d1eba7d349775518cd7 Author: Paul Thomas <[email protected]> Date: Tue Oct 13 11:39:06 2026 +0100 Fortran: [PDT] (4/16) Parameterized derived type errors [PR82173] 2026-10-13 Paul Thomas <[email protected]> gcc/fortran PR fortran/82173 * trans-decl.cc (gfc_trans_deferred_vars): gfc_allocate_pdt _comp cannot be called unless the symbol has a param_list. gcc/testsuite/ PR fortran/82173 * gfortran.dg/pdt_bug6.f90: New test. * gfortran.dg/pdt_bug17.f90: New test. Diff: --- gcc/fortran/trans-decl.cc | 3 ++- gcc/testsuite/gfortran.dg/pdt_bug17.f90 | 39 +++++++++++++++++++++++++++++++++ gcc/testsuite/gfortran.dg/pdt_bug6.f90 | 12 ++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc index e45d6643ea24..5d0d9ba1fda6 100644 --- a/gcc/fortran/trans-decl.cc +++ b/gcc/fortran/trans-decl.cc @@ -5162,7 +5162,8 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block) if (!sym->attr.dummy && !sym->attr.pointer) { tmp = gfc_init_default_pdt (sym, true); - if (!sym->attr.allocatable && tmp == NULL_TREE) + if (!sym->attr.allocatable && tmp == NULL_TREE + && sym->param_list) { tmp = gfc_allocate_pdt_comp (sym->ts.u.derived, sym->backend_decl, diff --git a/gcc/testsuite/gfortran.dg/pdt_bug17.f90 b/gcc/testsuite/gfortran.dg/pdt_bug17.f90 new file mode 100644 index 000000000000..2f76ae332892 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pdt_bug17.f90 @@ -0,0 +1,39 @@ +! { dg-do run } +! See attachment to PR82173 comment 10 - reproducers/bug17-final-rank-overload-ice.f90 +module mm + type :: t(k, n) + integer, kind :: k = 4 + integer, len :: n = 1 + real(k) :: v(n) + contains + final :: fin4, fin8, fin4_r1 + end type + integer :: tally = 0 +contains + subroutine fin4 (a) + type(t(4, *)), intent(inout) :: a + tally = tally + 1 + end subroutine + subroutine fin8 (a) + type(t(8, *)), intent(inout) :: a + tally = tally + 10 + end subroutine + subroutine fin4_r1 (a) + type(t(4, *)), intent(inout) :: a(:) + tally = tally + 100 + end subroutine +end module ! Segmentation fault here + + use mm + call foo +! Each final routine is called twice - assignment and leaving scope + if (tally /= 222) stop 1 +contains + subroutine foo + type(t(4, 2)) :: a, b(2) + type(t(8, 2)) :: c + a = t(4, 2)([1.0,2.0]) + b = [t(4, 2)([1.0,2.0]), t(4, 2)([3.0,4.0])] + c = t(8, 2)([1.0,2.0]) + end +end diff --git a/gcc/testsuite/gfortran.dg/pdt_bug6.f90 b/gcc/testsuite/gfortran.dg/pdt_bug6.f90 new file mode 100644 index 000000000000..3fa573e91895 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pdt_bug6.f90 @@ -0,0 +1,12 @@ +! { dg-do run } +! See attachment to PR82173 comment 10 - reproducers/bug6-alloc-self-component-ice.f90 +program g2 + type :: node(n) + integer, len :: n = 1 + real :: v(n) + type(node(:)), allocatable :: owned + end type + type(node(3)) :: head + head%v = 1.0 + if (allocated (head%owned)) stop 1 +end program ! Seg fault at trans-decl.cc:1697
