https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107425

--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Paul Thomas <[email protected]>:

https://gcc.gnu.org/g:bc98de3eddba8ecc8a3185014b1851d4cf16782e

commit r13-10299-gbc98de3eddba8ecc8a3185014b1851d4cf16782e
Author: Christopher Albert <[email protected]>
Date:   Fri Apr 3 17:50:05 2026 +0200

    fortran: Fix ICE with implicit variable in iterator depend clause
[PR107425]

    An implicitly typed variable used as a subscript in an OpenMP iterator
    depend clause (e.g., x(j) where j is implicit and only referenced in
    the clause) caused an ICE in gimplify_var_or_parm_decl because the
    variable's decl was never associated with a BIND_EXPR.

    The root cause is that gfc_match_iterator creates a block namespace
    (via gfc_build_block_ns) for iterator variables.  When the locator
    expression x(j) is parsed with gfc_current_ns set to this iterator
    namespace, the implicit variable j is created there rather than in the
    enclosing program namespace.  In gfc_finish_var_decl, the FL_LABEL
    check for BLOCK constructs matched before the omp_affinity_iterators
    check, routing j through add_decl_as_local.  Unlike real BLOCK
    construct variables, these never get a proper BIND_EXPR, so the
    gimplifier rejects them.

    Fixed by checking for omp_affinity_iterators before the FL_LABEL
    BLOCK construct check, and only treating actual iterator variables
    (those on the omp_affinity_iterators chain) as block-local.  Other
    variables in the iterator namespace are added to the enclosing
    function scope.

    2026-04-07  Paul Thomas  <[email protected]>

    gcc/fortran
            PR fortran/107425
            * trans-decl.cc (gfc_finish_var_decl): Check for
            omp_affinity_iterators namespace before FL_LABEL BLOCK check.
            Only route actual iterator variables through add_decl_as_local;
            add other variables to the enclosing function.

    gcc/testsuite
            PR fortran/107425
            * gfortran.dg/gomp/pr107425.f90: New test.

    Signed-off-by: Christopher Albert <[email protected]>
    (cherry picked from commit d26055fec8ef07d9b998ec3217b25507ad080fcf)

Reply via email to