GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
fortran

Fortran: Generate array bounds checks in the scalarizer block.

Moves array bounds checking code to the scalarizer block in gfc_conv_expr_descriptor to avoid use-before-definition issues.

This change refactors array bounds checking in the Fortran compiler to ensure that the bounds checking code is added to the same block the scalarizer uses to generate the array descriptor reference. Previously, the bounds checking code was added to the root block, which could lead to use-before-definition issues if the descriptor reference used variables generated by the scalarizer. This resolves PR125192 and PR125198.

In Details

In gfc_conv_expr_descriptor, array bounds checking code was added to the root block, separate from the scalarizer block used for array descriptor reference generation. This caused issues when the descriptor reference used variables generated by the scalarizer because they were being used in bounds checking code before their definition. This commit moves the bounds checking code to the outermost loop's preliminary block, where the scalarizer operates.

For Context

In Fortran, array bounds checking is a feature that ensures that when accessing elements of an array, the program doesn't try to access memory outside the allocated bounds of the array. This commit modifies the part of the Fortran compiler responsible for generating the array descriptor reference. Previously, the bounds checking code could be placed in a different block of code, leading to issues if the bounds checking relied on variables not yet defined. This change ensures that the bounds checking code is placed in the correct location, preventing these errors.

Filed Under: fortranbounds checkingscalarizer