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

Fortran: Introduce dedicated type for array ranks and dimensions

Fortran frontend uses a new, bounded type for array ranks and dimensions, improving type safety.

This commit introduces a new internal type, gfc_array_dim_rank_type, within the Fortran frontend to represent array ranks and dimensions. This type has stricter bounds (0 to GFC_MAX_DIMENSIONS) than the previously used signed char, providing better type safety and making these constraints known to the middle-end. The change affects array descriptors, loop iterations over dimensions, and constant initializations, with conversions added to prevent negative intermediate values.

In Details

The Fortran frontend (gfortran) now uses a dedicated type, gfc_array_dim_rank_type, for array ranks and dimensions, defined in trans-types.h/.cc. This new type, with explicit bounds (0 to GFC_MAX_DIMENSIONS), is used in array descriptors, constants (gfc_index_zero_node, gfc_index_one_node), and where dimensions are iterated. This change formalizes constraints previously handled implicitly or with wider types, requiring careful handling of signed-to-unsigned conversions and loop termination conditions to avoid underflow or incorrect bounds checking.

For Context
array rank
The number of dimensions in an array. A scalar has rank 0, a vector has rank 1, a matrix has rank 2, and so on.
array descriptor
A data structure used by the Fortran runtime to hold information about an array, such as its base address, bounds, and strides.
Fortran frontend
The part of the GCC compiler responsible for parsing and semantically analyzing Fortran source code, converting it into GCC's internal representation.
middle-end
The intermediate stage of the compiler (after the frontend and before the backend) where most general optimizations are applied to the compiler's intermediate representation.
Filed Under: fortrantype system