]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/87352 (Large stack usage with new gfortran)
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 14 Apr 2019 12:27:44 +0000 (12:27 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 14 Apr 2019 12:27:44 +0000 (12:27 +0000)
2019-04-14  Thomas Koenig  <tkoenig@gcc.gnu.org>

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

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

index e25bb0fb8dc6c7daf390acdf4b7554f281dbb432..190e476f4f078aed71a70034fb53b44ce8e180ae 100644 (file)
@@ -1,3 +1,11 @@
+2019-04-14  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       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  <anlauf@gmx.de>
 
        Backport from trunk
index 2d72e9570daa89c64ac0892e6d6c64c49d2ebe35..fdc10627a2a50887fe3383e726a603d40b37234f 100644 (file)
@@ -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;
 }
 
 
index a909d81b1aa1ccded2f3315f26d5647034c8468e..47b98bbd5ae121846978e9688797241ebdeb97ba 100644 (file)
@@ -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;
 
index 3e4395151c1ddbb5a56d43c29a1b764c2566d427..1eeab12e17a3114b80b7e8c399ea37ff9892a9b8 100644 (file)
@@ -1,3 +1,17 @@
+2019-04-14  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       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  <tkoenig@gcc.gnu.org>
+
+       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  <mliska@suse.cz>
 
        Backport from mainline
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" } }
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" } }