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

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Mikael Morin <[email protected]>:

https://gcc.gnu.org/g:a9299f6c4076d25c38e050c455454b54cfaa9dd3

commit r17-4529-ga9299f6c4076d25c38e050c455454b54cfaa9dd3
Author: Mikael Morin <[email protected]>
Date:   Mon Sep 21 16:52:05 2026 +0200

    fortran: Copy the span from the target descriptor in pointer assignments
[PR127448]

    Mark the _data field of array pointer class containers with the
    GFC_DECL_PTR_ARRAY_P flag, so that in pointer assignments, the span
assigned
    to the array descriptor is copied from the target descriptor span instead
of
    the class container size.

    Before this change, it was assumed that the size taken from the class
    container was the correct span value.  This was supposing all polymorphic
    arrays to be contiguous, which is not the case for a polymorphic pointer
    whose target is a parent object of an extended derived type object.

    The change tries to keep the current behaviour if possible, that is use
    the size from the class container if the array is known to be contiguous.
    I doubt the information is properly propagated everywhere, but it should
    be conservatively correct.

    The is_pointer_array hunk removes a condition that is redundant: the
    type of the operand 1 of a component ref is the type of the field, which
    is also the type of the component ref itself, which has already been
    checked before.  I suspect the condition to be a typo and should check
    operand 0 of the component ref.  If that was the case, this patch would
    remove it anyway.

            PR fortran/127448

    gcc/fortran/ChangeLog:

            * trans-array.cc (is_pointer_array): Remove redundant condition.
            (is_span_addressed_array): For polymorphic arrays, return false if
            the array is known to be contiguous.
            * trans-types.cc (gfc_get_derived_type): Also set the
            GFC_DECL_PTR_ARRAY_P flag for _data fields of class containers
            corresponding to polymorphic array pointers.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/pointer_assign_17.f90: New test.

Reply via email to