Fix DO CONCURRENT type-spec scope in Fortran.
Correctly scopes type-spec index-names in Fortran DO CONCURRENT constructs.
This commit resolves an issue in GCC’s Fortran frontend where the scope of an index-name within a DO CONCURRENT construct’s header was not correctly handled. Previously, type-spec references within the loop body could incorrectly refer to variables outside the construct, leading to wrong code generation. The fix replaces hand-written expression walkers with a gfc_traverse_expr callback and extends statement walkers to cover all expression forms, ensuring that references within the construct always bind to the intended index-name.
In Details
The Fortran frontend's DO CONCURRENT construct requires that any type-specifier used in its header (e.g., DO CONCURRENT (i = 1:10) where i is used in a type-spec like a(i)) establishes scope for that index-name throughout the construct body. The previous implementation used hand-written walkers (replace_forall_var, replace_in_expr_recursive, replace_in_code_recursive) that missed certain expression and statement forms. This led to references within the body incorrectly resolving to outer scope variables. The fix integrates gfc_traverse_expr for comprehensive expression travers…
- DO CONCURRENT
- A Fortran construct that specifies a loop whose iterations can be executed in any order or in parallel. It has stricter rules than a standard DO loop to ensure correctness in concurrent execution.
- type-spec
- In Fortran, a type specification can include array indexing or other associations that depend on loop variables or other defined entities.
- index-name
- The variable used to iterate over a loop, such as 'i' in 'DO i = 1, 10'.
- gfc_traverse_expr
- A callback mechanism in GCC's Fortran frontend used to recursively visit all nodes within an expression tree, ensuring all parts of the expression are processed.