re PR fortran/80477 ([OOP] Polymorphic function result generates memory leak)
authorPaul Thomas <pault@gcc.gnu.org>
Tue, 28 Aug 2018 11:35:52 +0000 (11:35 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Tue, 28 Aug 2018 11:35:52 +0000 (11:35 +0000)
commit1312bb902382cb4891673284f43ac095e80374cf
tree8ce6e0709fe7da9193539e9a2c66bf15130cb155
parent2c8861b7505cdc04377cd125565bb5ccadb29529
re PR fortran/80477 ([OOP] Polymorphic function result generates memory leak)

2017-08-28  Paul Thomas  <pault@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-28  Paul Thomas  <pault@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.

From-SVN: r263916
gcc/fortran/ChangeLog
gcc/fortran/trans-expr.c
gcc/fortran/trans-stmt.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/allocate_with_source_25.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/class_result_7.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/class_result_8.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/class_result_9.f90 [new file with mode: 0644]