https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51284
--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jerry DeLisle <[email protected]>: https://gcc.gnu.org/g:04d78e410bb86a4f14924a4b1829d7898128b6d6 commit r17-6575-g04d78e410bb86a4f14924a4b1829d7898128b6d6 Author: Jerry DeLisle <[email protected]> Date: Fri Nov 6 19:05:40 2026 -0800 fortran: [PR51284] Copy derived-type and CLASS actuals for VALUE dummies A VALUE dummy is associated with a copy of the actual argument (F2023 15.5.2.4). gfortran passed a derived type with allocatable components by value, sharing its component data with the actual argument, and gave a scalar CLASS dummy the actual's own container or, for a non-polymorphic or intrinsic actual, the address of a container where the callee expected the container. Pass a derived type with allocatable components by reference, like an array or a CHARACTER of non-constant length, because the caller frees the components of the copy and must see a DEALLOCATE done by the callee. This changes the calling convention for such dummies, which gfc_value_dummy_passed_byref decides for both gfc_sym_type and gfc_maybe_dereference_var. Pass a scalar CLASS dummy a container whose data is copied through the vtable. Copy only an actual argument that can share storage with a variable; a function result or a constructor is already an anonymous object, and the cleanup after the call frees it. This patch depends on the PR128478 patch, which adds conv_class_value_copy. Assisted-by: Claude Opus 5.5 PR fortran/51284 gcc/fortran/ChangeLog: * trans-expr.cc (gfc_maybe_dereference_var): Dereference a VALUE dummy that gfc_value_dummy_passed_byref passes by reference. (value_actual_shares_storage): New function. (conv_class_value_arg): New function. (conv_dummy_value): Pass a derived type with allocatable components by reference to a copy of a variable, or to the temporary. Pass the copy of a PDT by reference when the dummy is. Pass a null pointer for an absent argument to a dummy passed by reference. (gfc_conv_procedure_call): Use conv_class_value_arg for a scalar CLASS dummy with VALUE, repackaging an element of a class array as a class container. Copy an intrinsic actual argument for a CLASS(*) dummy with VALUE. * trans-types.cc (gfc_value_dummy_passed_byref): New function. (gfc_sym_type): Use it. * trans-types.h (gfc_value_dummy_passed_byref): Declare. gcc/testsuite/ChangeLog: * gfortran.dg/asan/value_dummy_copy_1.f90: New test. * gfortran.dg/value_19.f90: New test. * gfortran.dg/value_21.f90: New test. * gfortran.dg/value_22.f90: New test.
