re PR fortran/47637 ([OOP] Memory leak involving INTENT(OUT) CLASS argument w/ allocatable components)
2011-02-09 Janus Weil <janus@gcc.gnu.org> PR fortran/47637 * trans-decl.c (init_intent_out_dt): Handle CLASS arguments. 2011-02-09 Janus Weil <janus@gcc.gnu.org> PR fortran/47637 * gfortran.dg/auto_dealloc_2.f90: New. From-SVN: r169978
This commit is contained in:
parent
67b6839f99
commit
c7f1781582
4 changed files with 65 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
|||
2011-02-09 Janus Weil <janus@gcc.gnu.org>
|
||||
|
||||
PR fortran/47637
|
||||
* trans-decl.c (init_intent_out_dt): Handle CLASS arguments.
|
||||
|
||||
2011-02-08 Jerry DeLisle <jvdelisle@gcc.gnu.org>
|
||||
|
||||
* io.c (match_io_element): Do not set dt if not inquire.
|
||||
|
|
|
@ -3192,6 +3192,32 @@ init_intent_out_dt (gfc_symbol * proc_sym, gfc_wrapped_block * block)
|
|||
else if (f->sym->value)
|
||||
gfc_init_default_dt (f->sym, &init, true);
|
||||
}
|
||||
else if (f->sym && f->sym->attr.intent == INTENT_OUT
|
||||
&& f->sym->ts.type == BT_CLASS
|
||||
&& !CLASS_DATA (f->sym)->attr.class_pointer
|
||||
&& CLASS_DATA (f->sym)->ts.u.derived->attr.alloc_comp)
|
||||
{
|
||||
tree decl = build_fold_indirect_ref_loc (input_location,
|
||||
f->sym->backend_decl);
|
||||
tmp = CLASS_DATA (f->sym)->backend_decl;
|
||||
tmp = fold_build3_loc (input_location, COMPONENT_REF,
|
||||
TREE_TYPE (tmp), decl, tmp, NULL_TREE);
|
||||
tmp = build_fold_indirect_ref_loc (input_location, tmp);
|
||||
tmp = gfc_deallocate_alloc_comp (CLASS_DATA (f->sym)->ts.u.derived,
|
||||
tmp,
|
||||
CLASS_DATA (f->sym)->as ?
|
||||
CLASS_DATA (f->sym)->as->rank : 0);
|
||||
|
||||
if (f->sym->attr.optional || f->sym->ns->proc_name->attr.entry_master)
|
||||
{
|
||||
present = gfc_conv_expr_present (f->sym);
|
||||
tmp = build3_loc (input_location, COND_EXPR, TREE_TYPE (tmp),
|
||||
present, tmp,
|
||||
build_empty_stmt (input_location));
|
||||
}
|
||||
|
||||
gfc_add_expr_to_block (&init, tmp);
|
||||
}
|
||||
|
||||
gfc_add_init_cleanup (block, gfc_finish_block (&init), NULL_TREE);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
2011-02-09 Janus Weil <janus@gcc.gnu.org>
|
||||
|
||||
PR fortran/47637
|
||||
* gfortran.dg/auto_dealloc_2.f90: New.
|
||||
|
||||
2011-02-09 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
|
||||
|
||||
* gcc.dg/builtins-config.h: Remove __sgi handling.
|
||||
|
|
29
gcc/testsuite/gfortran.dg/auto_dealloc_2.f90
Normal file
29
gcc/testsuite/gfortran.dg/auto_dealloc_2.f90
Normal file
|
@ -0,0 +1,29 @@
|
|||
! { dg-do compile }
|
||||
! { dg-options "-fdump-tree-original" }
|
||||
!
|
||||
! PR 47637: [OOP] Memory leak involving INTENT(OUT) CLASS argument w/ allocatable components
|
||||
!
|
||||
! Contributed by Rich Townsend <townsend@astro.wisc.edu>
|
||||
|
||||
program test
|
||||
|
||||
type :: t
|
||||
integer, allocatable :: i(:)
|
||||
end type
|
||||
|
||||
type(t) :: a
|
||||
|
||||
call init(a)
|
||||
call init(a)
|
||||
|
||||
contains
|
||||
|
||||
subroutine init(x)
|
||||
class(t), intent(out) :: x
|
||||
allocate(x%i(1000))
|
||||
end subroutine
|
||||
|
||||
end program
|
||||
|
||||
! { dg-final { scan-tree-dump-times "__builtin_free" 2 "original" } }
|
||||
! { dg-final { cleanup-tree-dump "original" } }
|
Loading…
Add table
Reference in a new issue