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

Fortran DO CONCURRENT loop limits evaluated once.

Fortran DO CONCURRENT loop limits are now evaluated once at the start, aligning with the F2018 standard and preventing unexpected iteration changes.

This change addresses an issue in Fortran’s DO CONCURRENT loops where loop limits and step values were re-evaluated in each iteration. This behavior contradicted the F2018 standard, which specifies that limits should be evaluated once. The compiler now correctly evaluates the start, end, and step values once for outermost DO CONCURRENT constructs, ensuring predictable loop execution.

In Details

In GFortran's intermediate representation, the gfc_trans_forall_1 function previously recorded loop bounds and steps before they were stabilized into temporaries by gfc_make_safe_expr. This commit modifies gfc_trans_forall_1 to evaluate the start, end, and step expressions once for outermost DO CONCURRENT (and FORALL) constructs, storing these evaluated values. This adheres to the F2018 standard's interpretation (11.1.7.4.2) and prevents loop iterations from being altered by loop-variant computations within the loop body.

For Context
DO CONCURRENT
A Fortran construct that allows loop iterations to be executed in any order or concurrently, provided there are no loop-dependent data races.
F2018
The 2018 revision of the Fortran programming language standard.
Gfortran
GNU Fortran Compiler, the Fortran frontend for GCC.
Filed Under: fortranoptimization