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

Fix shadow variable bugs for DO CONCURRENT/FORALL type-spec.

Resolved issues with shadow variables in Fortran's DO CONCURRENT and FORALL constructs.

This commit addresses bugs related to shadow variables used with type specifications in Fortran’s DO CONCURRENT and FORALL statements. It ensures that each shadow variable gets a unique name, records the shadowed outer symbol, and prevents incorrect substitution into nested constructs that shadow the same symbol. This improves the robustness and correctness of Fortran’s handling of these constructs.

In Details

Fortran's DO CONCURRENT and FORALL statements allow for parallel execution and array assignment, respectively. When these constructs involve type specifications that introduce new variables (shadowing outer scope variables), managing these shadow variables correctly is crucial. This patch introduces shadow_outer_sym to track the outer symbol being shadowed, assigns unique numbered names to shadow variables to avoid clashes, and modifies resolve.cc to prevent recursing into nested FORALL/DO CONCURRENT statements that shadow the same symbol, thus fixing bugs related to symbol resolu…

For Context
DO CONCURRENT
A Fortran construct that specifies a loop whose iterations can be executed in any order and in parallel, without causing data races.
FORALL
A Fortran construct used for array assignment, allowing for simultaneous assignment to elements of an array based on specified index triplets or masks.
type-spec
In Fortran, this refers to specifying the data type of a variable or entity, often in contexts where it might implicitly declare a new variable.
shadow variable
A variable declared within an inner scope that has the same name as a variable in an outer scope. The inner variable 'shadows' the outer one, making it inaccessible within the inner scope.
Filed Under: fortranDO CONCURRENTFORALLscope