Commit dbb7247b by Janus Weil

re PR fortran/49466 (Memory leak with assignment of extended derived types)

2011-06-27  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/49466
	* trans-array.c (structure_alloc_comps): Make sure sub-components
	and extended types are correctly deallocated.


2011-06-27  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/49466
	* gfortran.dg/allocatable_scalar_9.f90: Modified.
	* gfortran.dg/extends_14.f03: Modified.

From-SVN: r175563
parent 5d8d1543
2011-06-27 Janus Weil <janus@gcc.gnu.org>
PR fortran/49466
* trans-array.c (structure_alloc_comps): Make sure sub-components
and extended types are correctly deallocated.
2011-06-21 Andrew MacLeod <amacleod@redhat.com> 2011-06-21 Andrew MacLeod <amacleod@redhat.com>
* trans-openmp.c: Add sync_ or SYNC__ to builtin names. * trans-openmp.c: Add sync_ or SYNC__ to builtin names.
......
...@@ -6682,18 +6682,22 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl, ...@@ -6682,18 +6682,22 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl,
switch (purpose) switch (purpose)
{ {
case DEALLOCATE_ALLOC_COMP: case DEALLOCATE_ALLOC_COMP:
if (cmp_has_alloc_comps && !c->attr.pointer)
{
/* Do not deallocate the components of ultimate pointer
components. */
comp = fold_build3_loc (input_location, COMPONENT_REF, ctype,
decl, cdecl, NULL_TREE);
rank = c->as ? c->as->rank : 0;
tmp = structure_alloc_comps (c->ts.u.derived, comp, NULL_TREE,
rank, purpose);
gfc_add_expr_to_block (&fnblock, tmp);
}
if (c->attr.allocatable && c->attr.dimension) if (c->attr.allocatable && c->attr.dimension)
{ {
comp = fold_build3_loc (input_location, COMPONENT_REF, ctype, comp = fold_build3_loc (input_location, COMPONENT_REF, ctype,
decl, cdecl, NULL_TREE); decl, cdecl, NULL_TREE);
if (cmp_has_alloc_comps && !c->attr.pointer)
{
/* Do not deallocate the components of ultimate pointer
components. */
tmp = structure_alloc_comps (c->ts.u.derived, comp, NULL_TREE,
c->as->rank, purpose);
gfc_add_expr_to_block (&fnblock, tmp);
}
tmp = gfc_trans_dealloc_allocated (comp); tmp = gfc_trans_dealloc_allocated (comp);
gfc_add_expr_to_block (&fnblock, tmp); gfc_add_expr_to_block (&fnblock, tmp);
} }
......
2011-06-27 Janus Weil <janus@gcc.gnu.org>
PR fortran/49466
* gfortran.dg/allocatable_scalar_9.f90: Modified.
* gfortran.dg/extends_14.f03: Modified.
2011-06-27 Janis Johnson <janisjo@codesourcery.com> 2011-06-27 Janis Johnson <janisjo@codesourcery.com>
* lib/target-supports-dg.exp (dg-require-effective-target): Return * lib/target-supports-dg.exp (dg-require-effective-target): Return
......
...@@ -49,7 +49,7 @@ if(allocated(na3%b3)) call abort() ...@@ -49,7 +49,7 @@ if(allocated(na3%b3)) call abort()
if(allocated(na4%b4)) call abort() if(allocated(na4%b4)) call abort()
end end
! { dg-final { scan-tree-dump-times "__builtin_free" 32 "original" } } ! { dg-final { scan-tree-dump-times "__builtin_free" 38 "original" } }
! { dg-final { cleanup-tree-dump "original" } } ! { dg-final { cleanup-tree-dump "original" } }
! { dg-final { cleanup-modules "m" } } ! { dg-final { cleanup-modules "m" } }
! { dg-do compile }
! { dg-options "-fdump-tree-original" }
!
! PR 49466: [4.6/4.7 Regression] Memory leak with assignment of extended derived types
!
! Contributed by Rich Townsend <townsend@astro.wisc.edu>
program evolve_aflow
implicit none
type :: state_t
real, allocatable :: U(:)
end type
type, extends(state_t) :: astate_t
end type
type(astate_t) :: a,b
allocate(a%U(1000))
a = b
end program
! { dg-final { scan-tree-dump-times "__builtin_free" 3 "original" } }
! { dg-final { cleanup-tree-dump "original" } }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment