[Patch, Fortran, F03] PR 55603: Memory leak with scalar allocatable function result

Janus Weil janus@gcc.gnu.org
Tue Aug 27 13:12:00 GMT 2013


Hi all,

here is a patch for PR 55603, which plugs a memory leak with scalar
allocatable function results.

To accomplish this, several things are done:
1) Allocatable scalar function results are passed as argument now and
returned by reference (just like array or character results, cf.
gfc_return_by_reference).
2) A temporary variable is inserted when calling a function with
allocatable scalar result (see gfc_conv_procedure_call).
3) The temporary is nullified before and freed after the call (which
is of course what plugs the memory leak in the end).

The first point requires some additional adjustments (see
create_function_arglist, gfc_trans_deferred_vars and
gfc_conv_variable).

In fact the patch is just a first step and does not handle more
advanced cases yet (like polymorphic allocatable scalar results,
finalization, etc). However, I wanted to get it out already, in order
to get some feedback on my approach before moving on. Also Tobias
mentioned that he has a draft patch for this PR, so he may have some
additions to it.

In any case, the patch fixes the original test case by Damian and
regtests cleanly on x86_64-unknown-linux-gnu. Ok for trunk?

Cheers,
Janus


2013-08-27  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/55603
    * trans-decl.c (create_function_arglist, gfc_trans_deferred_vars): Pass
    allocatable scalar results as argument.
    * trans-expr.c (gfc_conv_variable): Extra dereferencing for allocatable
    scalar results.
    (gfc_conv_procedure_call): Pass allocatable scalar results as argument.
    Create temporary, nullify and deallocate.
    * trans-types.c (gfc_return_by_reference): Treat allocatable scalars.


2013-08-27  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/55603
    * gfortran.dg/allocatable_scalar_result_1.f90: New.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr55603.diff
Type: application/octet-stream
Size: 6257 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20130827/23ca29e5/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: allocatable_scalar_result_1.f90
Type: application/octet-stream
Size: 450 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20130827/23ca29e5/attachment-0001.obj>


More information about the Gcc-patches mailing list