This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.

Attachment: pr55603.diff
Description: Binary data

Attachment: allocatable_scalar_result_1.f90
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]