Skip to content

Commit 4983e97

Browse files
author
Paul Thomas
committed
Fortran: Add non-PDT type extension to PDTs [PR122566]
2025-11-05 Paul Thomas <pault@gcc.gnu.org> gcc/fortran PR fortran/122566 * decl.cc (gfc_get_pdt_instance): Add non-PDT type exstention. gcc/testsuite/ PR fortran/122566 * gfortran.dg/pdt_68.f03: New test.
1 parent 071942e commit 4983e97

File tree

2 files changed

+59
-19
lines changed

2 files changed

+59
-19
lines changed

gcc/fortran/decl.cc

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4191,30 +4191,36 @@ gfc_get_pdt_instance (gfc_actual_arglist *param_list, gfc_symbol **sym,
41914191
to obtain the instance of the extended type. */
41924192
if (gfc_current_state () != COMP_DERIVED
41934193
&& c1 == pdt->components
4194-
&& (c1->ts.type == BT_DERIVED || c1->ts.type == BT_CLASS)
4195-
&& c1->ts.u.derived && c1->ts.u.derived->attr.pdt_template
4194+
&& c1->ts.type == BT_DERIVED
4195+
&& c1->ts.u.derived
41964196
&& gfc_get_derived_super_type (*sym) == c2->ts.u.derived)
41974197
{
4198-
gfc_formal_arglist *f;
4198+
if (c1->ts.u.derived->attr.pdt_template)
4199+
{
4200+
gfc_formal_arglist *f;
41994201

4200-
old_param_spec_list = type_param_spec_list;
4202+
old_param_spec_list = type_param_spec_list;
42014203

4202-
/* Obtain a spec list appropriate to the extended type..*/
4203-
actual_param = gfc_copy_actual_arglist (type_param_spec_list);
4204-
type_param_spec_list = actual_param;
4205-
for (f = c1->ts.u.derived->formal; f && f->next; f = f->next)
4206-
actual_param = actual_param->next;
4207-
if (actual_param)
4208-
{
4209-
gfc_free_actual_arglist (actual_param->next);
4210-
actual_param->next = NULL;
4211-
}
4204+
/* Obtain a spec list appropriate to the extended type..*/
4205+
actual_param = gfc_copy_actual_arglist (type_param_spec_list);
4206+
type_param_spec_list = actual_param;
4207+
for (f = c1->ts.u.derived->formal; f && f->next; f = f->next)
4208+
actual_param = actual_param->next;
4209+
if (actual_param)
4210+
{
4211+
gfc_free_actual_arglist (actual_param->next);
4212+
actual_param->next = NULL;
4213+
}
42124214

4213-
/* Now obtain the PDT instance for the extended type. */
4214-
c2->param_list = type_param_spec_list;
4215-
m = gfc_get_pdt_instance (type_param_spec_list, &c2->ts.u.derived,
4216-
&c2->param_list);
4217-
type_param_spec_list = old_param_spec_list;
4215+
/* Now obtain the PDT instance for the extended type. */
4216+
c2->param_list = type_param_spec_list;
4217+
m = gfc_get_pdt_instance (type_param_spec_list,
4218+
&c2->ts.u.derived,
4219+
&c2->param_list);
4220+
type_param_spec_list = old_param_spec_list;
4221+
}
4222+
else
4223+
c2->ts = c1->ts;
42184224

42194225
c2->ts.u.derived->refs++;
42204226
gfc_set_sym_referenced (c2->ts.u.derived);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
! { dg-do compile }
2+
! { dg-options "-fdump-tree-original" }
3+
!
4+
! Check the fix for PR122566.
5+
!
6+
! Contributed by Damian Rouson <damian@archaeologic.codes>
7+
!
8+
module double_precision_file_m
9+
implicit none
10+
11+
type file_t
12+
integer :: i
13+
end type
14+
15+
type, extends(file_t) :: double_precision_file_t
16+
end type
17+
18+
type, extends(double_precision_file_t) :: training_configuration_t(m)
19+
integer, kind :: m = kind(1.)
20+
end type
21+
22+
contains
23+
pure module function training_configuration()
24+
type(training_configuration_t) training_configuration
25+
training_configuration%file_t = file_t(42) ! Needed parent type to be introduced explicitly
26+
end function
27+
end module
28+
29+
use double_precision_file_m
30+
type(training_configuration_t) :: x
31+
x = training_configuration ()
32+
if (x%i /= 42) stop 1
33+
end
34+
! { dg-final { scan-tree-dump-times "double_precision_file_t.file_t" 2 "original" } }

0 commit comments

Comments
 (0)