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

--- Comment #4 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:1892effc2f4b99665a3aa5d1d27aa093475a158d

commit r17-5783-g1892effc2f4b99665a3aa5d1d27aa093475a158d
Author: Mikael Morin <[email protected]>
Date:   Sun Nov 1 14:30:49 2026 +0100

    fortran: Use span indexing for polymorphic target dummies [PR127827]

    Index polymorphic dummy arrays having the TARGET attribute using the span
    from the array descriptor instead of the size from the class container.

    A previous change by Jerry (r17-3342) introduced the infrastructure to
    suport span indexing for non-polymorphic target dummy arguments.  The
    testcase provided in the PR and added here shows that it has to be extended
    to support the polymorphic case, as done by this change.

    The main change amends the existing function gfc_dummy_requires_direct_arg
    to allow polymorphic entities.  It is more complex that just removing the
    condition excluding BT_CLASS type, because the DIMENSION, ALLOCATABLE and
    POINTER attributes are stored differently on polymorphic entities than on
    non-polymorphic ones, and the same goes for the array spec.  So a mostly
    rewritten copy of the existing conditions is added for the CLASS case.

    Allowing polymorphic entities in gfc_dummy_requires_direct_arg enables the
    creation of a span variable by gfc_build_dummy_array_decl, stored in the
    GFC_DECL_SPAN of the local array decl, and whose presence is sufficient to
    enable span indexing in the non-polymorphic case.  But it is not sufficient
    for polymorphic entities, because the function gfc_maybe_dereference_var
    generates a dereference for them around the local array decl reference, and
    GFC_DECL_GET_SPAN of a dereference returns NULL_TREE.  So a preliminary
step
    is added in gfc_get_array_span to unwrap the pointer dereference, making
the
    value present in GFC_DECL_SPAN visible, which activates span indexing.

            PR fortran/127827

    gcc/fortran/ChangeLog:

            * symbol.cc (gfc_dummy_requires_direct_arg): Allow CLASS type.
            * trans-array.cc (get_main_decl): New function.
            (gfc_get_array_span): If the array decl is not passed as input
            directly, get it first before querying the span on it.

    gcc/testsuite/ChangeLog:

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

Reply via email to