Fortran: Fix an excess finalization during allocation [PR104272]
authorPaul Thomas <pault@gcc.gnu.org>
Fri, 14 Apr 2023 10:14:00 +0000 (11:14 +0100)
committerPaul Thomas <pault@gcc.gnu.org>
Fri, 14 Apr 2023 10:15:12 +0000 (11:15 +0100)
commitb0e85485fbf042abccee5c0a9eb499da386c8db3
tree2d26d1a45f52c274db699e9e80f993b37520b27c
parentbf24f2db2841b97bc5e86bf9294d61eef32f83b3
Fortran: Fix an excess finalization during allocation [PR104272]

2023-04-14  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/104272
* gfortran.h : Add expr3_not_explicit bit field to gfc_code.
* resolve.cc (resolve_allocate_expr): Set bit field when the
default initializer is applied to expr3.
* trans-stmt.cc (gfc_trans_allocate): If expr3_not_explicit is
set, do not deallocate expr3.

gcc/testsuite/
PR fortran/104272
* gfortran.dg/class_result_8.f90 : Number of builtin_frees down
from 6 to 5 without memory leaks.
* gfortran.dg/finalize_52.f90: New test
gcc/fortran/gfortran.h
gcc/fortran/resolve.cc
gcc/fortran/trans-stmt.cc
gcc/testsuite/gfortran.dg/class_result_8.f90
gcc/testsuite/gfortran.dg/finalize_52.f90 [new file with mode: 0644]