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

Fortran END ASSOCIATE restores old CLASS array selector.

Fixes a double-free bug in Fortran's ASSOCIATE/SELECT TYPE constructs involving polymorphic arrays.

A bug in GCC’s Fortran front-end could lead to a double-free error when using ASSOCIATE or SELECT TYPE with polymorphic array selectors. Upon exiting these blocks, the compiler incorrectly copied back the original array descriptor, even after the selector had been deallocated. This commit corrects the behavior by ensuring this copy-back only occurs for SELECT RANK constructs, which can have dynamically allocated or pointer-assigned selectors. Other ASSOCIATE and SELECT TYPE constructs, where the selector is not POINTER or ALLOCATABLE, do not require this copy-back.

In Details

The trans_associate_var function in gcc/fortran/trans-stmt.cc has been modified to fix a double-free issue related to polymorphic array selectors in ASSOCIATE and SELECT TYPE. Previously, the end of these blocks would copy the entry descriptor back into the selector, even if the selector was ALLOCATABLE or POINTER and had been deallocated within the block. This caused a double-free. The fix restricts this copy-back behavior to SELECT RANK constructs, where the associate name can be allocated or pointer-assigned. For other constructs, this copy-back is unnecessary as the associat…

For Context
ASSOCIATE
A Fortran construct that allows a temporary name to be associated with a variable or expression within a block of code.
SELECT TYPE
A Fortran construct that allows code execution to branch based on the dynamic type of a polymorphic variable.
SELECT RANK
A Fortran construct similar to SELECT TYPE, but it branches based on the dynamic rank (number of dimensions) of a polymorphic array.
polymorphic
In Fortran, a variable that can have different dynamic types during program execution.
descriptor
A data structure that contains information about a variable, such as its type, rank, bounds, and whether it is allocated.
double-free
A memory corruption error that occurs when a block of memory is deallocated (freed) more than once.
Filed Under: fortranbugfixmemory error