[Bug fortran/53800] [OOP] Wrong copy-in/copy-out when passing CLASS array to assumed-shape TYPE

"cvs-commit at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53800

--- Comment #5 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:f3943597388db4846386b6d5a18d33ebf80ea96c

commit r17-3342-gf3943597388db4846386b6d5a18d33ebf80ea96c
Author: Jerry DeLisle <[email protected]>
Date:   Mon Aug 10 09:37:01 2026 -0700

    fortran: [PR53800] Wrong copy-in/out with array actual to TARGET dummy

    An actual argument whose elements are spaced by more than the element
    size - a CLASS array, or a component of a derived-type array - was
    copied in and out when passed to a TARGET or POINTER dummy, so pointers
    associated with the dummy went stale on return.

    Such an actual argument is now passed with a descriptor of its own,
    whose element type is that of the subobject and whose span is the
    element size of the array, as is already done for a pointer assignment
    to a subobject of an array.  The dummy addresses its elements through
    that span.  Passing it on to a dummy that requires contiguous storage
    copies it, but only if it turns out not to be contiguous.

            PR fortran/53800

    gcc/fortran/ChangeLog:

            * gfortran.h (gfc_is_span_addressed_dummy): New prototype.
            * symbol.cc (gfc_is_span_addressed_dummy): New function.
            * expr.cc (is_subref_array): Return true for a span addressed
dummy.
            * trans.h (gfc_get_span_descriptor): New prototype.
            * trans.cc (gfc_get_span_descriptor): New function returning the
            descriptor that carries a pointer array decl's span.
            (get_array_span): Use it, including for character types.
            * trans-array.cc (is_pointer_array): Note in the comment that the
            tree must be a descriptor.
            (span_addressed_array): New function returning the decl that
            provides the span of an array.
            (gfc_get_array_span): Use it.
            (gfc_conv_scalarized_array_ref, gfc_conv_array_ref): Likewise, so
            that a descriptorless dummy is addressed by its span.
            (gfc_get_dataptr_offset): Likewise and dereference a spanned
            character element.
            (gfc_conv_expr_descriptor): Describe a subobject of the array
            elements by a new descriptor when no temporary is made.
            * trans-decl.cc (gfc_build_dummy_array_decl): Use
            gfc_is_span_addressed_dummy to mark the dummy as a pointer array.
            (gfc_get_symbol_decl): Likewise.
            * trans-expr.cc (is_subobject_ref): New function.
            (copy_in_out_allowed): Take the actual argument.  Use
            gfc_is_span_addressed_dummy and keep the copy for an actual
            argument with a vector subscript.
            (gfc_conv_gfc_desc_to_cfi_desc): Remove the now duplicate
offsetting
            of the data pointer for a subobject reference.
            (gfc_class_array_data_assign): Also copy the span field.
            (gfc_conv_procedure_call): Use copy_in_out_allowed to skip
            copy-in/copy-out for a class array reference, a class array
function
            result and a subref array.  Pass a spanned descriptor instead and
            make the copy of a span addressed dummy conditional on it not being
            contiguous.
            * trans-intrinsic.cc (gfc_conv_is_contiguous_expr): Check the span
            of a span addressed dummy against the element length.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/c_loc_test_22.f90: Update dump patterns for span
            addressing.
            * gfortran.dg/class_to_type_5.f90: New test.
            * gfortran.dg/class_to_type_6.f90: New test.
            * gfortran.dg/class_to_type_7.f90: New test.
            * gfortran.dg/class_to_type_8.f90: New test.
            * gfortran.dg/class_to_type_9.f90: New test.

    libgomp/ChangeLog:

            * testsuite/libgomp.oacc-fortran/host_data-5.F90: Update the
            privatization notes for the packing of a TARGET dummy.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.