Hello All, As with (4/16), I have used a Jerry + Claude review: "Patch: 5 (bug7/22) Verdict: Works, but bug7 still fails for a partially initialized parent, and the bug22 fix treats the symptom. Root-cause fix in alt-bug7-13-22.diff"
The attached fixes the problem with partially initialized parents, which even simplifies the patch. I have slightly rejigged the fix for bug 22 to be more consistent with existing handling of imported PDTs. I am not sure what the "root cause" fix can look like nor do I have a copy of the fix. I am trying to avoid using LLMs for the fixes themselves but will flag it up as an when I relent! Pushed as r17-5110. Cheers Paul On Thu, 8 Oct 2026 at 13:33, Paul Richard Thomas <[email protected]> wrote: > > bug7-parent-default-init.f90 fails in runtime with: > STOP 1 > because the default initializer of 'plain' is not applied to the extended > type. > > bug22-import-pdt-ice.f90 fails with: > 26 | use t2_m > | 1 > internal compiler error: in gfc_release_symbol, at fortran/symbol.cc:3412 > 0x1f5d97f internal_error(char const*, ...) > ../../gcc/gcc/diagnostic-global-context.cc:787 > 0x451689 fancy_abort(char const*, int, char const*) > ../../gcc/gcc/diagnostics/context.cc:1813 > > Although these are distinct errors, it was convenient to bundle these > fixes together. > The first two chunks fix bug7. The default initializer for the non-PDT > parent requires a check that all its component initializers are > present. Bug22 is fixed by ensuring that the reference count of > instance is bumped up again to allow for its double passage through > gfc_free_namespace: Once for the interface and again through the > module. > > Passes regtesting on FC44/x86_64. OK for mainline. > > Cheers > > Paul
From 66f0a0bbeb547d5852b4bf5ff370cce79d4b6943 Mon Sep 17 00:00:00 2001 From: Paul Thomas <[email protected]> Date: Tue, 13 Oct 2026 12:06:58 +0100 Subject: [PATCH] Fortran: [PDT] (5/16) Parameterized derived type errors [PR82173] 2026-10-13 Paul Thomas <[email protected]> gcc/fortran PR fortran/82173 * decl.cc (gfc_get_pdt_instance): An new, imported PDT instance must have its refs incremented. Provide a non-PDT parent type with a default initializer. Set 'instance' referenced. gcc/testsuite/ PR fortran/82173 * gfortran.dg/pdt_bug7.f90: New test. * gfortran.dg/pdt_bug22.f90: New test. --- gcc/fortran/decl.cc | 7 +++++- gcc/testsuite/gfortran.dg/pdt_bug22.f90 | 30 +++++++++++++++++++++++++ gcc/testsuite/gfortran.dg/pdt_bug7.f90 | 18 +++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/pdt_bug22.f90 create mode 100644 gcc/testsuite/gfortran.dg/pdt_bug7.f90 diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc index 01b6109940c..46a1dece891 100644 --- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -4323,6 +4323,7 @@ gfc_get_pdt_instance (gfc_actual_arglist *param_list, gfc_symbol **sym, gfc_get_sym_tree (instance->name, gfc_current_ns, &s, false, &gfc_current_locus); s->n.sym = instance; + instance->refs++; } s->n.sym->attr.imported = 1; s->import_only = 1; @@ -4442,6 +4443,9 @@ gfc_get_pdt_instance (gfc_actual_arglist *param_list, gfc_symbol **sym, } instance->attr.extension = c2->ts.u.derived->attr.extension + 1; + /* Add the parent initializer. */ + if (!IS_PDT (c2) && !c2->ts.u.derived->attr.alloc_comp) + c2->initializer = gfc_generate_initializer (&c2->ts, false); continue; } @@ -4683,8 +4687,9 @@ gfc_get_pdt_instance (gfc_actual_arglist *param_list, gfc_symbol **sym, if (ptr_seen) instance->attr.pointer_comp = 1; - + gfc_set_sym_referenced (instance); gfc_commit_symbol (instance); + if (ext_param_list) *ext_param_list = type_param_spec_list; *sym = instance; diff --git a/gcc/testsuite/gfortran.dg/pdt_bug22.f90 b/gcc/testsuite/gfortran.dg/pdt_bug22.f90 new file mode 100644 index 00000000000..effc9e43cbb --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pdt_bug22.f90 @@ -0,0 +1,30 @@ +! { dg-do run } +! See attachment to PR82173 comment 10 - reproducers/bug22-import-pdt-ice.f90 +module t_m + type :: t(n) + integer, len :: n = 1 + real :: v(n) + end type +end module t_m + +module t2_m + use t_m + interface + subroutine handler (a) + import :: t + type(t(*)), intent(in) :: a + end subroutine + end interface +end module t2_m + +subroutine handler (a) + use t_m + type(t(*)), intent(in) :: a + if (any (int (a%v) /= [1,2,3])) stop 1 +end subroutine + + use t2_m + type(t(3)) :: x + x%v = [1.,2.,3.] + call handler (x) +end diff --git a/gcc/testsuite/gfortran.dg/pdt_bug7.f90 b/gcc/testsuite/gfortran.dg/pdt_bug7.f90 new file mode 100644 index 00000000000..7762b97a416 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pdt_bug7.f90 @@ -0,0 +1,18 @@ +! { dg-do run } +! See attachment to PR82173 comment 10 - reproducers/bug7-parent-default-init.f90 +program h1 + type :: plain + integer :: id = 11 + real :: weight = 0.5 + end type + type, extends(plain) :: para(n) + integer, len :: n = 1 + real :: v(n) + end type + type(para(3)) :: p + type(plain) :: q + if (p%id /= 11) stop 1 ! Inherited values + if (int (200.0 * p%weight) /= 100) stop 2 ! were zero + if (q%id /= 11) stop 3 + if (int (200.0 * q%weight) /= 100) stop 4 +end program -- 2.56.0
