You will be pleased to know that the remaining patches in this series
will follow at a later date, since the fixes are not completed.
(16/16) is a placeholder for any remaining issues or tidying up.

bug18-namelist-pdt-ice.f90 segfaulted in runtime because the pdt_array
data pointer, rather than its descriptor, was being passed to the
library 'set_nml_val_dim'. The fix is in the second chunk and is
trivial. The first chunk is optional and was added because I got sick
and tired of trying to follow the casting:-)

Passes regtesting on FC44/x86_64. OK for mainline.

Cheers

Paul
From 09063a4b7b412eec100eff5ea9ac6332ed4d758d Mon Sep 17 00:00:00 2001
From: Paul Thomas <[email protected]>
Date: Wed, 7 Oct 2026 12:04:20 +0100
Subject: [PATCH] Fortran: [meta-bug] [PDT] Parameterized derived type errors
 [PR82173]

2026-10-07  Paul Thomas  <[email protected]>

gcc/fortran
	PR fortran/82173
	* trans-io.cc (nml_get_addr_expr): Remove nops from the data
	pointer.
	(transfer_namelist_element): Pass descriptors of PDT arrays.

gcc/testsuite/
	PR fortran/82173
	* gfortran.dg/pdt_bug18.f90: New test.
---
 gcc/fortran/trans-io.cc                 |  8 +++++++-
 gcc/testsuite/gfortran.dg/pdt_bug18.f90 | 17 +++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pdt_bug18.f90

diff --git a/gcc/fortran/trans-io.cc b/gcc/fortran/trans-io.cc
index 48fdaa5e733..732c59250d9 100644
--- a/gcc/fortran/trans-io.cc
+++ b/gcc/fortran/trans-io.cc
@@ -1650,7 +1650,10 @@ nml_get_addr_expr (gfc_symbol * sym, gfc_component * c,
     tmp = gfc_class_data_get (tmp);
 
   if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (tmp)))
-    tmp = gfc_conv_array_data (tmp);
+    {
+      tmp = gfc_conv_array_data (tmp);
+      STRIP_NOPS (tmp);
+    }
   else
     {
       if (!POINTER_TYPE_P (TREE_TYPE (tmp)))
@@ -1820,6 +1823,9 @@ transfer_namelist_element (stmtblock_t * block, const char * var_name,
 
   for ( n_dim = 0 ; n_dim < rank ; n_dim++ )
     {
+      if (c && c->attr.pdt_array)
+	decl = TREE_OPERAND (nml_get_addr_expr (sym, c, base_addr), 0);
+
       tmp = build_call_expr_loc (input_location,
 			     iocall[IOCALL_SET_NML_VAL_DIM], 5,
 			     dt_parm_addr,
diff --git a/gcc/testsuite/gfortran.dg/pdt_bug18.f90 b/gcc/testsuite/gfortran.dg/pdt_bug18.f90
new file mode 100644
index 00000000000..2f263241e20
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pdt_bug18.f90
@@ -0,0 +1,17 @@
+! { dg-do run }
+program q1
+  type :: t(n)
+    integer, len :: n = 1
+    integer :: v(n)
+  end type
+  type(t(5)) :: a
+  namelist /grp/ a
+  a%v = [1,2,3,4,5]
+  open (10, status='SCRATCH')
+  write (10, nml=grp)
+  a%v = 0
+  rewind (10)
+  read (10, nml=grp)
+  close (10)
+  if (any (a%v /= [1,2,3,4,5])) stop 1
+end program
-- 
2.55.0

Reply via email to