GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
fortran

fortran: Don't reuse original descriptors for packed arrays [PR125998]

Fixes Fortran packed array descriptor creation to ensure correct memory layout and bounds.

This commit corrects how GCC’s Fortran frontend, gfortran, handles descriptors for packed arrays, particularly in the context of array parameters and transposed arrays. It prevents the reuse of original array descriptors, which could lead to incorrect memory layouts (e.g., using transposed data for non-transposed packed arrays). The changes ensure that new descriptors are created and that bounds, strides, and offsets are correctly calculated based on the packed array’s actual dimensions and layout, addressing issues related to PR97592 and PR125998.

In Details

The gfc_conv_array_parameter function in trans-array.cc is modified to always create a new descriptor for packed arrays, addressing PR125998. Previously, for non-transposed arrays, it would reuse the original descriptor and only modify the data pointer, which is invalid if the original descriptor's contiguity or stride information doesn't match the packed representation. For transposed arrays, it incorrectly reused the original bounds instead of those of the transposed view. This change ensures that new descriptors are created, bounds are copied correctly from the *transposed* view (if ap…

For Context
Descriptor
In Fortran, a data structure that describes an array, including its dimensions, bounds, element type, strides, and memory location. It's used by the runtime to access array elements correctly.
Packed Array
An array where elements are stored contiguously in memory without any padding between them, potentially differing from the default memory layout. This is often used for efficiency or interoperability.
Transpose
In the context of arrays, transposing typically refers to switching the row and column indices. For a 2D array, the element at (i, j) moves to (j, i). Fortran's TRANSPOSE intrinsic creates a view of an array with swapped dimensions.
gfortran
The GNU Fortran compiler, part of the GCC suite. It implements the Fortran language standards.
Strides
The number of memory locations between consecutive elements of an array along a particular dimension. Strides are crucial for calculating memory addresses, especially for multi-dimensional or non-contiguous arrays.
Filed Under: fortrangfortranarraydescriptor