[Patch, Fortran] PR 41586: Allocatable _scalars_ are never auto-deallocated

Janus Weil janus@gcc.gnu.org
Mon Oct 19 14:50:00 GMT 2009


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?


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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr41586.diff
Type: text/x-diff
Size: 6327 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20091019/57107c5d/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: auto_dealloc_1.f90
Type: application/octet-stream
Size: 1068 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20091019/57107c5d/attachment.obj>


More information about the Fortran mailing list