[Bug fortran/110626] [13/14/15/16/17 regression] Duplicated finalization in derived
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sun Aug 16 11:42:47 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110626
--- Comment #26 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Paul Thomas <pault@gcc.gnu.org>:
https://gcc.gnu.org/g:a03222414043b7155a76f7e564fb688ac5ac7bb6
commit r17-3317-ga03222414043b7155a76f7e564fb688ac5ac7bb6
Author: Christopher Albert <albert@tugraz.at>
Date: Sun Aug 16 13:34:44 2026 +0100
Fortran: [13-17 regression] Fix duplicated finalization [PR110626]
For a derived-type intrinsic assignment with a component defined
assignment, generate_component_assignments emitted a whole-derived-type
assignment and a defined-assignment call on a temporary copy of the old
lhs. The whole assignment finalized the lhs. The INTENT(OUT) argument
then finalized the stale temporary instead of the real component, so both
finalizations saw the old value.
For a scalar lhs without pointer or allocatable components, mark the
whole-derived-type assignment finalize_only. It finalizes the lhs
without copying the structure, then assigns each component separately.
The component defined assignment acts on the real component and its
INTENT(OUT) finalization sees the value left by the first finalization.
Array lhs assignments remain on the existing path because their
component-wise expansion needs scalarization. The allocatable-component
case remains PR fortran/57696.
Assisted-by: GPT-5.6-sol (OpenAI)
Assisted-by: Claude (Anthropic)
2026-08-16 Christopher Albert <albert@tugraz.at>
gcc/fortran
PR fortran/110626
* gfortran.h : Add finalize_only bitfield to gfc_expr.
* resolve.cc (generate_component_assignments): If the lhs has
no pointer or allocatable components, set use_finalize_only to
false. Otherwise it equals finalizable_lhs. Use the value to
set the expr1 finalize_only field and add the assignment to the
chain. If use_finalize_only is false, free the statements and
transfer the value to the final result.
* trans-expr.cc (gfc_trans_assignment_1): If expr1 is finalize_
only emit an empty statement.
gcc/testsuite/
PR fortran/110626
* gfortran.dg/finalize_62.f90: New test.
Signed-off-by: Christopher Albert <albert@tugraz.at>
More information about the Gcc-bugs
mailing list