https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49802

--- Comment #23 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:110e034f8b58529576c7168bfcda6d42336fbf89

commit r17-3645-g110e034f8b58529576c7168bfcda6d42336fbf89
Author: Jerry DeLisle <[email protected]>
Date:   Sun Aug 23 18:27:40 2026 -0700

    fortran: [PR49802]-1 Add a deep copy mode to gfc_conv_subref_array_arg

    This is the shared infrastructure the rest of the PR49802 series builds
    on.  It changes no behaviour for any existing caller.

    gfc_conv_subref_array_arg gains a DEEP_COPY argument, defaulting to
    false, which it passes on to gfc_trans_scalar_assign so that the
    temporary is given allocatable components of its own rather than
    sharing those of the actual argument.  The components are freed again
    once the call has returned.  Only INTENT_IN is supported, since writing
    the temporary back would leave the actual argument holding the freed
    component pointers.

    Two latent problems in the pass_optional path are fixed at the same
    time.  The pointer was assigned the address of the descriptor rather
    than the descriptor, and the string length was not copied back out of
    the private gfc_se, so a CHARACTER actual argument reached
    gfc_conv_missing_dummy with none.  Neither is reachable today: the only
    caller that passes SYM, and so the only one that can set pass_optional,
    is gfc_conv_array_parameter, which also sets check_contiguous.  Both
    are exercised by the last patch of this series, where an absent
    optional actual argument is passed to a VALUE dummy.

            PR fortran/49802

    gcc/fortran/ChangeLog:

            * trans.h (gfc_conv_subref_array_arg): Add DEEP_COPY argument.
            * trans-expr.cc (gfc_conv_subref_array_arg): Take DEEP_COPY and
            pass it on to gfc_trans_scalar_assign; deallocate the allocatable
            components of the temporary after the call.  Dereference the
            descriptor when setting the pointer for an optional argument that
            is not also checked for contiguity, and pass the string length
            back to the caller's gfc_se.

Reply via email to