From b81f7b83631be7dedcdcf44eed6dd575ada3ac23 Mon Sep 17 00:00:00 2001 From: Thomas Koenig Date: Sat, 6 Apr 2019 22:10:28 +0000 Subject: [PATCH] re PR fortran/87352 (Large stack usage with new gfortran) 2019-04-06 Thomas Koenig PR fortran/87352 * 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-06 Thomas Koenig PR fortran/87352 * gfortran.dg/finalize_28.f90: Adjust count of __builtin_free. * gfortran.dg/finalize_33.f90: Likewise. * gfortran.dg/finalize_34.f90: New test. From-SVN: r270184 --- gcc/fortran/ChangeLog | 7 +++++++ gcc/fortran/class.c | 4 ++++ gcc/fortran/gfortran.h | 1 + gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/gfortran.dg/finalize_28.f90 | 2 +- gcc/testsuite/gfortran.dg/finalize_33.f90 | 2 +- gcc/testsuite/gfortran.dg/finalize_34.f90 | 25 +++++++++++++++++++++++ 7 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/finalize_34.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index ca1728041c3..563ef9d3a3c 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2019-04-06 Thomas Koenig + + PR fortran/87352 + * 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-06 Thomas Koenig PR fortran/89981 diff --git a/gcc/fortran/class.c b/gcc/fortran/class.c index 3f23556e726..8a1f43f116c 100644 --- a/gcc/fortran/class.c +++ b/gcc/fortran/class.c @@ -911,6 +911,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 (); @@ -1038,6 +1041,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 caf5e528c7e..be975cda074 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -1094,6 +1094,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 2c8de7a9720..4208625d09e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2019-04-06 Thomas Koenig + + PR fortran/87352 + * gfortran.dg/finalize_28.f90: Adjust count of __builtin_free. + * gfortran.dg/finalize_33.f90: Likewise. + * gfortran.dg/finalize_34.f90: New test. + 2019-04-06 Thomas Koenig PR fortran/89981 diff --git a/gcc/testsuite/gfortran.dg/finalize_28.f90 b/gcc/testsuite/gfortran.dg/finalize_28.f90 index f0c9665252f..597413b2dd3 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_33.f90 b/gcc/testsuite/gfortran.dg/finalize_33.f90 index 3857e4485ee..2205f9eed7f 100644 --- a/gcc/testsuite/gfortran.dg/finalize_33.f90 +++ b/gcc/testsuite/gfortran.dg/finalize_33.f90 @@ -116,4 +116,4 @@ contains ! (iii) mci_template end program main_ut ! { dg-final { scan-tree-dump-times "__builtin_malloc" 17 "original" } } -! { dg-final { scan-tree-dump-times "__builtin_free" 20 "original" } } +! { dg-final { scan-tree-dump-times "__builtin_free" 19 "original" } } diff --git a/gcc/testsuite/gfortran.dg/finalize_34.f90 b/gcc/testsuite/gfortran.dg/finalize_34.f90 new file mode 100644 index 00000000000..e2f02a5c51c --- /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" } }