[Patch, Fortran] PR 41586: Allocatable _scalars_ are never auto-deallocated
Janus Weil
janus@gcc.gnu.org
Mon Oct 19 16:45:00 GMT 2009
2009/10/19 Janus Weil <janus@gcc.gnu.org>:
> Hi all,
>
> here is a patch for automatic deallocation of allocatable scalars.
>
> There are four cases to take care of (which correspond to the
> subroutines 'a' to 'd' in the test case):
> 1) plain allocatable scalar variables
> 2) allocatable scalar CLASS variables
> 3) allocatable scalar components
> 4) allocatable scalar CLASS components
>
> All of them work fine now AFAICS.
> One aside, however: There is a strange thing in the dump for case 'c'
> (not necessarily connected to this patch):
>
> struct t1 m;
>
> m.j = 0B;
> {
> struct t1 D.1388;
> struct t1 t1.0;
>
> t1.0.pi = 3.1400001049041748046875e+0;
> t1.0.j = 0B;
> D.1388 = m;
> m = t1.0;
> if (D.1388.j != 0B)
> {
> __builtin_free ((void *) D.1388.j);
> }
> D.1388.j = 0B;
> }
>
> If I'm not mistaken, this code was generated by "gfc_init_default_dt"
> to handle the default initialization of the variable 'm'. But it's not
> quite clear to me why we need two temporaries here, or why this
> 'D.1388' needs to be freed although it's barely used at all (and
> certainly not allocated). Maybe someone can enlighten me on this
> matter.
>
>
> The patch was regtested on x86_64-unknown-linux-gnu. Ok for trunk?
As noted by Dominique (thanks!), my test case misses a
! { dg-options "-fdump-tree-original" }
I admit I did not test it with dejagnu before posting (but I swear I
would have done so before committing ;)
Btw: Since I can never remember those dg-crazy syntax bits, I added
some missing stuff to the following wiki page:
http://gcc.gnu.org/wiki/TestCaseWriting
Cheers,
Janus
> 2009-10-19 Janus Weil <janus@gcc.gnu.org>
>
> PR fortran/41586
> * parse.c (parse_derived): Correctly set 'alloc_comp' and 'pointer_comp'
> for CLASS variables.
> * trans-array.c (structure_alloc_comps): Handle deallocation and
> nullification of allocatable scalar components.
> * trans-decl.c (gfc_get_symbol_decl): Remember allocatable scalars for
> automatic deallocation.
> (gfc_trans_deferred_vars): Automatically deallocate allocatable scalars.
>
>
> 2009-10-19 Janus Weil <janus@gcc.gnu.org>
>
> PR fortran/41586
> * gfortran.dg/auto_dealloc_1.f90: New test case.
>
More information about the Fortran
mailing list