GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
fortran

Fix Fortran ALLOCATE status handling for overflow and already allocated arrays

Ensures correct error status reporting in Fortran's ALLOCATE statement for allocatable arrays, especially when size calculations overflow or the array is alrea…

This Fortran compiler commit corrects how the ALLOCATE statement handles error conditions for allocatable arrays. It refines the logic to ensure that the STATUS parameter is correctly set to an ‘already allocated’ error only when the array is indeed already allocated, even if the size calculation would otherwise cause an overflow or exceed virtual memory. Pointer arrays are handled separately, as they can only encounter a virtual memory error.

In Details

This patch modifies the Fortran frontend's array allocation logic, specifically gfc_array_allocate and gfc_allocate_allocatable in trans-array.cc and trans.cc. It addresses PR128656 by ensuring that for allocatable arrays, the ALLOCATE statement with a STATUS keyword correctly reports an allocation error if the array is already allocated, prior to attempting size calculations that might overflow or exceed memory limits. For pointer arrays, the behavior is distinct, only considering memory limits.

For Context
ALLOCATE statement
A Fortran statement used to dynamically allocate memory for allocatable arrays or pointers.
allocatable array
A type of array in Fortran whose size is determined at runtime. Memory for it must be explicitly allocated using the ALLOCATE statement.
STATUS keyword
An optional keyword in Fortran's ALLOCATE statement that allows the program to check the success or failure of the allocation operation by assigning an error code to a named integer variable.
virtual memory
A memory management technique implemented by the operating system that allows a computer to compensate for physical memory shortages by temporarily transferring data from random access memory (RAM) to disk storage.
pointer array
In Fortran, an array that is associated with a pointer. Unlike allocatable arrays, pointers can be associated with existing memory or dynamically allocated memory.
Filed Under: fortrancompilerruntimeerror handling