All, The attached patch fixes PR 83183. Previously, attempting to generate initializers for allocatable components of the same derived type triggered infinite recursion. Passes regression tests. OK for trunk and gcc-8-branch?
>From 01961cc78b8ecd5272521098ae3166516a49dcd1 Mon Sep 17 00:00:00 2001 From: Fritz Reese <fritzore...@gmail.com> Date: Mon, 25 Jun 2018 17:51:00 -0400 Subject: [PATCH] PR fortran/83183 Fix infinite recursion occurring with -finit-derived generating initializers for allocatable derived-type components. gcc/fortran/ * expr.c (component_initializer): Do not generate initializers with allocatable BT_DERIVED components. --- gcc/fortran/expr.c | 1 + gcc/testsuite/gfortran.dg/init_flag_18.f90 | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/init_flag_18.f90
From 01961cc78b8ecd5272521098ae3166516a49dcd1 Mon Sep 17 00:00:00 2001 From: Fritz Reese <fritzore...@gmail.com> Date: Mon, 25 Jun 2018 17:51:00 -0400 Subject: [PATCH] PR fortran/83183 Fix infinite recursion occurring with -finit-derived generating initializers for allocatable derived-type components. gcc/fortran/ * expr.c (component_initializer): Do not generate initializers with allocatable BT_DERIVED components. --- gcc/fortran/expr.c | 1 + gcc/testsuite/gfortran.dg/init_flag_18.f90 | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/init_flag_18.f90 diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 5103a5cc990..468f45ec488 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -4422,6 +4422,7 @@ component_initializer (gfc_typespec *ts, gfc_component *c, bool generate) Some components should never get initializers. */ if (c->initializer || !generate || (ts->type == BT_CLASS && !c->attr.allocatable) + || (ts->type == BT_DERIVED && c->attr.allocatable) || c->attr.pointer || c->attr.class_pointer || c->attr.proc_pointer) diff --git a/gcc/testsuite/gfortran.dg/init_flag_18.f90 b/gcc/testsuite/gfortran.dg/init_flag_18.f90 new file mode 100644 index 00000000000..9ab00a9afce --- /dev/null +++ b/gcc/testsuite/gfortran.dg/init_flag_18.f90 @@ -0,0 +1,19 @@ +! { dg-do compile } +! { dg-options "-finit-derived" } +! +! PR fortran/83183 +! +! Test a regression where -finit-derived recursed infinitely generating +! initializers for allocatable components of the same derived type. +! + +program pr83183 + type :: linked_list + type(linked_list), allocatable :: link + integer :: value + end type + type(linked_list) :: test + allocate(test % link) + print *, test%value + print *, test%link%value +end program -- 2.12.2