Am 17.11.26 um 5:40 PM schrieb Jerry DeLisle:
See attached patch. When the body of a DO CONCURRENT defines a variable
that a concurrent-limit or concurrent-step references, the serial loops
use the new value, so the wrong iterations run. The start of an inner
concurrent-control is affected too, since its loop restarts on each
outer iteration. The fix has the loops of an outermost FORALL or DO
CONCURRENT use the values gfc_trans_forall_1 already evaluates up front.
A nested FORALL keeps the current code because its limits may use the
outer index-names.

The fix is one hunk in gfc_trans_forall_1 in trans-stmt.cc. The rest is
the new test. Its second case changes the limits of the inner loop. Its
third case changes those of the outer loop.

Regression tested on x86_64.

OK for mainline?

Yes, this is OK.

Thanks for the patch!

Harald

Regards,

Jerry

---

fortran: [PR128793] Evaluate DO CONCURRENT limits and step once

The serial loops of DO CONCURRENT read the variables referenced by the
concurrent-limits and concurrent-steps again during the iterations, so a
body that defined one changed which iterations ran, although F2018
11.1.7.4.2 evaluates them once.  This was because gfc_trans_forall_1
recorded the end and step for the loops before gfc_make_safe_expr copied
them into temporaries, and never made the start safe.  For an outermost
FORALL or DO CONCURRENT, evaluate the start once too and have the loops
use the evaluated start, end and step.  A nested FORALL is left alone,
since its limits may use the outer index-names.

Assisted-by: Claude Opus 5.5

        PR fortran/128793

gcc/fortran/ChangeLog:

        * trans-stmt.cc (gfc_trans_forall_1): For an outermost construct,
        evaluate the start once and use the evaluated start, end and step
        in the loops.

gcc/testsuite/ChangeLog:

        * gfortran.dg/do_concurrent_16.f90: New test.

Reply via email to