Fix shared memory pool exhaustion reporting in libgfortran
Coarray ALLOCATE and FORM TEAM now correctly report shared memory pool exhaustion in libgfortran, preventing segfaults.
Previously, if a Fortran coarray ALLOCATE or FORM TEAM operation exceeded libgfortran’s shared memory pool, it would incorrectly return a success status (STAT=0). This led to the allocator returning a pointer beyond the pool’s bounds, resulting in a segfault on first access. This change modifies the allocator to return a null pointer upon exhaustion, allowing ALLOCATE and FORM TEAM to report the error via STAT= or terminate gracefully, and other allocations to terminate the image with an informative message.
In Details
The libgfortran/caf/shmem/alloc.c's get_memory_by_id_internal function now returns NULL when the shared memory pool is exhausted, instead of continuing to allocate memory. This change affects _gfortran_caf_register and _gfortran_caf_form_team to handle this NULL return by reporting STAT= or terminating. Other allocation functions like allocator_shared_malloc_or_die are used to ensure allocation failures lead to image termination with a message. This addresses PR127751.
- coarray
- A Fortran language feature that allows for parallel programming by providing a mechanism for images (concurrent processes) to directly access data on other images.
- ALLOCATE
- A Fortran statement used to dynamically allocate memory for variables, including coarrays.
- FORM TEAM
- A Fortran statement used to create a new team of images for coarray execution.
- STAT=
- An optional argument in Fortran's ALLOCATE and other statements that receives an error status code. A value of 0 typically indicates success.
- shared memory pool
- A region of memory accessible by multiple processes or images, used here by libgfortran for coarray communication.