re PR fortran/87352 (Large stack usage with new gfortran)
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 6 Apr 2019 22:10:28 +0000 (22:10 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 6 Apr 2019 22:10:28 +0000 (22:10 +0000)
2019-04-06  Thomas Koenig  <tkoenig@gcc.gnu.org>

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  <tkoenig@gcc.gnu.org>

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
gcc/fortran/class.c
gcc/fortran/gfortran.h
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/finalize_28.f90
gcc/testsuite/gfortran.dg/finalize_33.f90
gcc/testsuite/gfortran.dg/finalize_34.f90 [new file with mode: 0644]

index ca1728041c31359825881ba6caee9cfc0c698feb..563ef9d3a3c241e9a39e777680c34780bf622a0a 100644 (file)
@@ -1,3 +1,10 @@
+2019-04-06  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       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  <tkoenig@gcc.gnu.org>
 
        PR fortran/89981
index 3f23556e726bdb0ec6424d14e1a68e3b5b6269ad..8a1f43f116c52e92984d6bc79eabcce2e5ed90c6 100644 (file)
@@ -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;
 }
 
 
index caf5e528c7e01dc5db84008f2759a226e1972ca4..be975cda0749a0cd423929cf8a7c1e4d51a628af 100644 (file)
@@ -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;
 
index 2c8de7a97200755de6f1078c598909c3656f23c5..4208625d09e3ebb720303a2ad3c8d75c0eccf2b5 100644 (file)
@@ -1,3 +1,10 @@
+2019-04-06  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       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  <tkoenig@gcc.gnu.org>
 
        PR fortran/89981
index f0c9665252f46a455fe8877b0dae51f9af381e02..597413b2dd3f14b82472fd3600442a891d036854 100644 (file)
@@ -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" } }
index 3857e4485ee8b9ec7ceeb9baaa64c5d6ea9df8fb..2205f9eed7f2bfb1c6ab3f9bb493ee56bf97cc56 100644 (file)
@@ -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 (file)
index 0000000..e2f02a5
--- /dev/null
@@ -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" } }