libgfortran: Fix coarray part allocation for child teams
libgfortran's coarray implementation now allocates memory for all program images, preventing buffer overflows in child teams.
This commit corrects an issue in libgfortran’s coarray implementation where memory for coarray parts was allocated based on the current team’s size, not the total program images. This led to buffer overflows when child teams were formed, as images with indices exceeding the child team’s size wrote past the allocated memory. The fix ensures that a coarray part is allocated for every image in the program, guaranteeing sufficient space regardless of team structure.
In Details
In libgfortran/caf/shmem.c, the _gfortran_caf_register function previously sized the coarray part allocation based on the current_team->num_images. This caused buffer overflows in child teams where image_index could exceed current_team->num_images. The commit changes the allocation size to num_images_total, ensuring that a coarray part is allocated for every image in the program. This resolves memory corruption issues when forming child teams and accessing their coarray data.
- coarray
- A Fortran language feature providing built-in support for parallel programming by allowing direct access to data on other processing units (images).
- image
- In Fortran coarrays, an 'image' is an independent sequential execution stream, analogous to a process or thread.
- team
- A subset of images within a coarray program, allowing for more flexible and structured parallel communication patterns.
- buffer overflow
- A condition where a program attempts to write data beyond the allocated buffer, potentially corrupting adjacent memory.