From f537563bd4214fe2ea1a881480c93867be2445a3 Mon Sep 17 00:00:00 2001 From: Thomas Koenig Date: Sun, 14 Apr 2019 12:27:44 +0000 Subject: [PATCH] re PR fortran/87352 (Large stack usage with new gfortran) 2019-04-14 Thomas Koenig PR fortran/87352 Backport from trunk * gfortran.h (gfc_component): Add finalized field. * class.c (finalize_component): If the component is already finalized, return early. Set component->finalized on exit. 2019-04-14 Thomas Koenig Backport from trunk PR fortran/87352 * gfortran.dg/finalize_28.f90: Adjust count of __builtin_free. * gfortran.dg/finalize_34.f90: New test. From-SVN: r270352 --- gcc/fortran/ChangeLog | 8 ++++++++ gcc/fortran/class.c | 4 ++++ gcc/fortran/gfortran.h | 1 + gcc/testsuite/ChangeLog | 14 +++++++++++++ gcc/testsuite/gfortran.dg/finalize_28.f90 | 2 +- gcc/testsuite/gfortran.dg/finalize_34.f90 | 25 +++++++++++++++++++++++ 6 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/finalize_34.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index e25bb0fb8dc6..190e476f4f07 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,11 @@ +2019-04-14 Thomas Koenig + + PR fortran/87352 + Backport from trunk + * gfortran.h (gfc_component): Add finalized field. + * class.c (finalize_component): If the component is already + finalized, return early. Set component->finalized on exit. + 2019-04-10 Harald Anlauf Backport from trunk diff --git a/gcc/fortran/class.c b/gcc/fortran/class.c index 2d72e9570daa..fdc10627a2a5 100644 --- a/gcc/fortran/class.c +++ b/gcc/fortran/class.c @@ -899,6 +899,9 @@ finalize_component (gfc_expr *expr, gfc_symbol *derived, gfc_component *comp, if (!comp_is_finalizable (comp)) return; + if (comp->finalized) + return; + e = gfc_copy_expr (expr); if (!e->ref) e->ref = ref = gfc_get_ref (); @@ -1026,6 +1029,7 @@ finalize_component (gfc_expr *expr, gfc_symbol *derived, gfc_component *comp, sub_ns); gfc_free_expr (e); } + comp->finalized = true; } diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index a909d81b1aa1..47b98bbd5ae1 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -1058,6 +1058,7 @@ typedef struct gfc_component struct gfc_typebound_proc *tb; /* When allocatable/pointer and in a coarray the associated token. */ tree caf_token; + bool finalized; } gfc_component; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3e4395151c1d..1eeab12e17a3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,17 @@ +2019-04-14 Thomas Koenig + + Backport from trunk + PR fortran/87352 + * gfortran.dg/finalize_28.f90: Adjust count of __builtin_free. + * gfortran.dg/finalize_34.f90: New test. + +2019-04-14 Thomas Koenig + + Backport from trunk + PR fortran/87352 + * gfortran.dg/finalize_28.f90: Adjust count of __builtin_free. + * gfortran.dg/finalize_34.f90: New test. + 2019-04-11 Martin Liska Backport from mainline diff --git a/gcc/testsuite/gfortran.dg/finalize_28.f90 b/gcc/testsuite/gfortran.dg/finalize_28.f90 index f0c9665252f4..597413b2dd3f 100644 --- a/gcc/testsuite/gfortran.dg/finalize_28.f90 +++ b/gcc/testsuite/gfortran.dg/finalize_28.f90 @@ -21,4 +21,4 @@ contains integer, intent(out) :: edges(:,:) end subroutine coo_dump_edges end module coo_graphs -! { dg-final { scan-tree-dump-times "__builtin_free" 6 "original" } } +! { dg-final { scan-tree-dump-times "__builtin_free" 5 "original" } } diff --git a/gcc/testsuite/gfortran.dg/finalize_34.f90 b/gcc/testsuite/gfortran.dg/finalize_34.f90 new file mode 100644 index 000000000000..e2f02a5c51c5 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/finalize_34.f90 @@ -0,0 +1,25 @@ +! { dg-do compile } +! { dg-additional-options "-fdump-tree-original" } +! PR 87352 - this used to cause an excessive number of deallocations. +module testmodule + implicit none + public + + type :: evtlist_type + real, allocatable, dimension(:) :: p1 + real, allocatable, dimension(:) :: p2 + real, allocatable, dimension(:) :: p3 + real, allocatable, dimension(:) :: p4 + end type evtlist_type + + type :: evtlistlist_type + type(evtlist_type) :: evtlist(1:1) + end type evtlistlist_type + +end module testmodule + +program main + use testmodule + type(evtlist_type), dimension(10) :: a +end program main +! { dg-final { scan-tree-dump-times "__builtin_free" 8 "original" } } -- 2.47.2