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

--- Comment #4 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:0235a09b822088b8bea3bc3fccbea3a8fc773d29

commit r17-5793-g0235a09b822088b8bea3bc3fccbea3a8fc773d29
Author: Jerry DeLisle <[email protected]>
Date:   Wed Oct 28 13:27:21 2026 -0400

    libgfortran: [PR127751] caf_shmem: catch overflowing coarray sizes

    caf_register multiplied the per-image size by the number of images in
    size_t without checking for overflow.  A large request could wrap to a
    small size, succeed with STAT=0, and leave the coarray far too small.
    The size arithmetic now saturates at SIZE_MAX, and the allocator rejects
    sizes too large to round up to a power of two, so the request fails
    through STAT= as an exhausted pool does.

    The buffer of a collective reduction had the same overflow on the number
    of images; its size now saturates as well, and the failure is reported
    through STAT= and ERRMSG= of the collective.

    Assisted-by: Claude Opus 5.5

            PR libfortran/127751

    libgfortran/ChangeLog:

            * caf/shmem.c (mul_size_sat): New function.
            (_gfortran_caf_register): Use it for all size computations and
            saturate the alignment of the size.
            * caf/shmem/allocator.c (allocator_shared_malloc): Return a null
            pointer for sizes that cannot be rounded up to a power of two.
            * caf/shmem/collective_subroutine.c (collsub_reduce_array):
            Saturate the buffer size on overflow.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/coarray/alloc_pool_exhausted_2.f90: New test.

Reply via email to