Hello Jerry,

This looks good to me. replace_in_code_recursive is doing pretty much
the same thing as decl.cc(gfc_insert_kind_parameter_exprs).
Unfortunately, the two are so different as to make it pointless to
combine them.

OK for mainline and, given that it is for Damian's formal package, 16-branch.

Cheers

Paul

On Sun, 30 Aug 2026 at 20:20, Jerry D <[email protected]> wrote:
>
> See attached patch.
>
> This bug found in testing of the formal package courtesy of Damian Rouson.
>
> Regression tested on x86_64.
>
> OK for mainline and backport to 16?
>
> Regards.
>
> Jerry
>
> ---
>
>      fortran: [PR127128] wrong code with DO CONCURRENT type-spec index-name
>
>      A type-spec in a DO CONCURRENT concurrent-header gives the index-name
>      construct scope.  The front end implements this by creating a shadow
>      variable and substituting it for the index-name throughout the construct
>      body.  The hand-written walkers that perform the substitution covered
>      only a subset of the expression and statement forms, so references left
>      behind still pointed at the enclosing scope's variable.  The construct
>      then indexed with an unrelated, often undefined, value.
>
>      Replace the expression walker with a gfc_traverse_expr callback so that
>      every expression form is covered, and extend the statement walker to the
>      forms it was missing: the branch chains of IF and WHERE constructs, the
>      allocate-objects of ALLOCATE and DEALLOCATE, and the case lists of
>      SELECT TYPE and SELECT RANK.
>
>              PR fortran/127128
>
>      gcc/fortran/ChangeLog:
>
>              * resolve.cc (replace_forall_var): New function.
>              (replace_in_expr_recursive): Traverse with gfc_traverse_expr
>              instead of walking the expression by hand.
>              (replace_in_code_recursive): Substitute in the whole branch chain
>              of IF and WHERE constructs, in the allocate-objects of ALLOCATE
>              and DEALLOCATE, and in SELECT TYPE and SELECT RANK case lists.
>
>      gcc/testsuite/ChangeLog:
>
>              * gfortran.dg/do_concurrent_typespec_5.f90: New test.
>

Reply via email to