Discussion:
[Patch, fortran] PRs 80477 and 86481 - memory leaks following function calls.
Paul Richard Thomas
2018-08-26 15:54:49 UTC
Permalink
This patch grew from the original patch for PR80477 because it was
found that the array valued version leaked memory as well. Then, I
found that the assignment in class_result_9.f90 ICEd, while trying to
fix the array valued test, class_result_8.f90. Finally, while I was
about it, I fixed PR86481, which is similar but involves cleaning up
of the source expression after allocation.

Most of the time was spent on persuading the final calls to appear in
the right place. All the tests have been checked with valgrind.

Bootstrapped and regtested on FC28/x86_64 - OK for trunk?

Cheers

Paul

2017-08-26 Paul Thomas <***@gcc.gnu.org>

PR fortran/80477
* trans-expr.c (gfc_conv_procedure_call): Allocatable class
scalar results being passed to a derived type formal argument
are finalized if possible. Otherwise, rely on existing code for
deallocation. Make the deallocation of allocatable result
components conditional on finalization not taking place. Make
the freeing of data components after finalization conditional
on the data being NULL.
(gfc_trans_arrayfunc_assign): Change the gcc_assert to a
condition to return NULL_TREE.
(gfc_trans_assignment_1): If the assignment is class to class
and the rhs expression must be finalized but the assignment
is not marked as a polymorphic assignment, use the vptr copy
function instead of gfc_trans_scalar_assign.

PR fortran/86481
* trans-expr.c (gfc_conv_expr_reference): Do not add the post
block to the pre block if the expression is to be finalized.
* trans-stmt.c (gfc_trans_allocate): If the expr3 must be
finalized, load the post block into a finalization block and
add it right at the end of the allocation block.

2017-08-26 Paul Thomas <***@gcc.gnu.org>

PR fortran/80477
* gfortran.dg/class_result_7.f90: New test.
* gfortran.dg/class_result_8.f90: New test.
* gfortran.dg/class_result_9.f90: New test.

PR fortran/86481
* gfortran.dg/allocate_with_source_25.f90: New test.
Thomas Koenig
2018-08-27 19:26:17 UTC
Permalink
Hi Paul,
Post by Paul Richard Thomas
Bootstrapped and regtested on FC28/x86_64 - OK for trunk?
OK, and thanks for the patch!

Regards

Thomas
Paul Richard Thomas
2018-08-28 12:36:44 UTC
Permalink
Committed as r263916.

Thanks for taking a look over it, Thomas.

Paul
Post by Thomas Koenig
Hi Paul,
Post by Paul Richard Thomas
Bootstrapped and regtested on FC28/x86_64 - OK for trunk?
OK, and thanks for the patch!
Regards
Thomas
--
"If you can't explain it simply, you don't understand it well enough"
- Albert Einstein
Loading...