[gcc r16-8035] Fortran: gfortran PDT component access [PR97818]
Paul Thomas
pault@gcc.gnu.org
Thu Mar 12 11:21:34 GMT 2026
https://gcc.gnu.org/g:9ff20883d44ef568805a4a8f731977e77a1c9459
commit r16-8035-g9ff20883d44ef568805a4a8f731977e77a1c9459
Author: Paul Thomas <pault@gcc.gnu.org>
Date: Thu Mar 12 11:21:23 2026 +0000
Fortran: gfortran PDT component access [PR97818]
2026-03-12 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/97818
* trans-decl.cc (gfc_trans_deferred_vars): Make sure that the
result symbol is referenced before allocating parameterized
components.
gcc/testsuite/
PR fortran/97818
* gfortran.dg/pdt_88.f03: New test.
Diff:
---
gcc/fortran/trans-decl.cc | 1 +
gcc/testsuite/gfortran.dg/pdt_88.f03 | 78 ++++++++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+)
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 4dfb390e4ebb..8649d0fbc819 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -4910,6 +4910,7 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block)
&& proc_sym != proc_sym->result) ? proc_sym->result : NULL;
if (sym && !sym->attr.allocatable && !sym->attr.pointer
+ && sym->attr.referenced
&& IS_PDT (sym) && !gfc_has_default_initializer (sym->ts.u.derived))
{
gfc_init_block (&tmpblock);
diff --git a/gcc/testsuite/gfortran.dg/pdt_88.f03 b/gcc/testsuite/gfortran.dg/pdt_88.f03
new file mode 100644
index 000000000000..31bc2e827f8f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pdt_88.f03
@@ -0,0 +1,78 @@
+! { dg-do compile }
+!
+! Test the fix for pr97818. Used to ICE in structure_alloc_comps, at
+! fortran/trans-array.cc:10211 because the parameterized function results
+! had not been set.
+!
+! Contributed by Adam Jermyn <adamjermyn@gmail.com>
+!
+module my_type_module
+
+ implicit none
+ private
+ public :: my_type, &
+ assignment(=), &
+ operator(+)
+
+ type :: my_type(n)
+ integer, len :: n ! Length of array of independent variables
+ real :: val
+ real :: d1
+ real :: d2
+ real :: d1Array(n)
+ real :: d1_d2
+ real :: d1_d1Array(n)
+ real :: d2_d1Array(n)
+ real :: d1_d2_d1Array(n)
+ end type my_type
+
+ interface assignment(=)
+ module procedure assign_from_self
+ end interface assignment(=)
+
+ interface operator(+)
+ module procedure add_self
+ module procedure add_self_real
+ end interface operator(+)
+
+
+ contains
+
+ subroutine assign_from_self(this, other)
+ type(my_type(n=*)), intent(inout) :: this
+ type(my_type(n=this%n)), intent(in) :: other
+ end subroutine assign_from_self
+
+ function add_self(x, y) result(binary)
+ type(my_type(n=*)), intent(in) :: x
+ type(my_type(n=*)), intent(in) :: y
+ type(my_type(n=x%n)) :: binary
+ end function add_self
+
+ function add_self_real(x, y) result(unary)
+ type(my_type(n=*)), intent(in) :: x
+ real, intent(in) :: y
+ type(my_type(n=x%n)) :: unary
+ end function add_self_real
+
+end module my_type_module
+
+
+program test_auto_diff
+ use my_type_module
+
+ call do_test_auto_diff_2var_order3_dArray(5)
+
+ contains
+
+ subroutine do_test_auto_diff_2var_order3_dArray(n)
+ integer, intent(in) :: n
+ type(my_type(n=n)) :: x, y, z
+
+ z = (x + 2.0) + ((x + 2.0) + 1.0)
+
+ end subroutine do_test_auto_diff_2var_order3_dArray
+
+
+
+end program test_auto_diff
More information about the Gcc-cvs
mailing list