https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80477
--- Comment #24 from Paul Thomas <pault at gcc dot gnu.org> --- Author: pault Date: Tue Aug 28 11:35:52 2018 New Revision: 263916 URL: https://gcc.gnu.org/viewcvs?rev=263916&root=gcc&view=rev Log: 2017-08-28 Paul Thomas <pa...@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 <pa...@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. Added: trunk/gcc/testsuite/gfortran.dg/allocate_with_source_25.f90 trunk/gcc/testsuite/gfortran.dg/class_result_7.f90 trunk/gcc/testsuite/gfortran.dg/class_result_8.f90 trunk/gcc/testsuite/gfortran.dg/class_result_9.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/trans-expr.c trunk/gcc/fortran/trans-stmt.c trunk/gcc/testsuite/ChangeLog