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

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Paul Thomas <[email protected]>:

https://gcc.gnu.org/g:75be60856749d85ef29358e6ab4f3c48c128589c

commit r17-2855-g75be60856749d85ef29358e6ab4f3c48c128589c
Author: Paul Thomas <[email protected]>
Date:   Fri Jul 24 15:05:46 2026 +0100

    Fortran: Auto deallocate coarrays, allocated in team blocks [PR126205]

    Gfortran was not compliant with F2018(11.1.5.2), which requires that
    coarrays that are allocated within a team block are deallocated immediately
    before END TEAM.

    This the fourth variant of the patch; the main differences being whether
    the code is located on resolve.cc, split between resolve.cc and
    trans-stmt.cc or, as here, split between parse.cc, match.cc and st.cc.
    The main attraction of the latter scheme is that coarray.cc and
    resolve.cc do the main job of preparing the code for translation.

    The team context is tracked using a vector of team namespaces, which is
    pushed at CHANGE TEAM and popped at END TEAM. The allocate expressions
    are stashed in a vector hash_map, keyed on the namespace. The allocate
    expressions are stored while the ALLOCATE statments are being matched.
    They are then recovered before end in parse_change_team and sent off
    for automatic deallocation in st.cc(deallocate_allocated_coarrays.

    The use of st.cc for functions generating chunks of code is a pointer
    to something that I have been eyeing for a long time, which is to
    extract all such functions from class.cc and resolve.cc so that they
    can be refactored to use common chunks. This, however, is for another
    time!

    2026-07-24  Paul Thomas  <[email protected]>

    gcc/fortran
            PR fortran/126205
            * gfortran.h: Add prototype for deallocate_allocated_coarrays.
            hash_map team_allocated_coarrays, vector team_context_stack and
            prototype for get_current_team_context.
            * match.cc (gfc_match_allocate): Capture allocate expressions
            of allocatable coarrays and stash in team_allocated_coarrays.
            * parse.cc (parse_change_team): Push team context. When end is
            seen, create the code to deallocate allocated coarrays in this
            context, using deallocate_allocated_coarrays.
            * st.cc (get_guarded_dealloc): Generate code to produce
            IF (ALLOCATED (expr)) DEALLOCATE (expr).
            (deallocate_allocated_coarrays): Modify the final array ref of
            the allocate expressions and call get_guarded_dealloc.

    gcc/testsuite/
            PR fortran/126205
            * gfortran.dg/coarray/team_allocated_coarrays.f90: New test.

Reply via email to