Fortran: Fixes wrong code in DO CONCURRENT with ASSOCIATE blocks
GCC's Fortran compiler fixes a code generation error in DO CONCURRENT constructs that involve ASSOCIATE blocks and inline type-spec iterators.
This commit resolves a code generation bug in GCC’s Fortran compiler where DO CONCURRENT constructs containing ASSOCIATE blocks referencing inline type-spec iterators would produce incorrect code. The replace_in_code_recursive function previously lacked a case for EXEC_BLOCK (associate constructs), causing it to silently skip over both the ASSOCIATE selector expressions and its body during iterator replacements. The fix adds handling for EXEC_BLOCK, ensuring proper iteration over selector expressions and correct recursion into the body’s namespace to replace shadow iterator references.
In Details
This change in gcc/fortran/resolve.cc addresses a code generation issue (PR125532) where replace_in_code_recursive failed to properly handle EXEC_BLOCK nodes within DO CONCURRENT constructs when processing inline type-spec iterators. Previously, ASSOCIATE blocks containing such iterators were implicitly skipped, leading to incorrect shadow iterator replacement. The modification adds an explicit EXEC_BLOCK case, enabling the function to correctly iterate over selector target expressions via replace_in_expr_recursive and ensuring proper recursion into the ASSOCIATE body's code l…
For Context
This update to GCC, the Fortran compiler, fixes a bug where code generated for programs using specific parallel programming features would be incorrect. In Fortran, DO CONCURRENT allows loops to run in parallel, and ASSOCIATE blocks let you temporarily rename complex expressions or variables for readability. The problem occurred when an ASSOCIATE block inside a DO CONCURRENT loop referred to a special kind of internal 'iterator' variable. The compiler's system for replacing these internal iterator references was failing to look inside ASSOCIATE blocks, causing it to miss necessary changes. This fix teaches the compiler to correctly process ASSOCIATE blocks within DO CONCURRENT loops, ensuring that your parallel Fortran code behaves as expected and produces correct results.