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

            Bug ID: 128793
           Summary: DO CONCURRENT re-reads concurrent-limit and
                    concurrent-step after the body changes them
           Product: gcc
           Version: 16.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jvdelisle at gcc dot gnu.org
  Target Milestone: ---

F2018 11.1.7.4.2 says the concurrent-limits and concurrent-steps are
evaluated once, before any iteration.  gfortran's serial lowering reads
the variables again, so a body that defines a variable referenced by a
limit or step changes which iterations run.

program main
  implicit none
  integer :: s, k, a(5)
  s = 2
  a = 0
  do concurrent (k = 1:5:s)
     a(k) = k
     if (k == 1) s = 1
  end do
  print '(5i2)', a
  if (any (a /= [1, 0, 3, 0, 5])) stop 1
end program main

$ gfortran pr.f90 && ./a.out
 1 2 3 0 0
STOP 1

Expected " 1 0 3 0 5".  The limits of a concurrent-control that is not
the outermost loop are re-read the same way, e.g. the start and end of
i in "do concurrent (i = lo:hi:st, j = 1:3)" when the body changes lo
and hi.

Cause: gfc_trans_forall_1 records the end and step for the generated
loops (this_forall->end/step) before gfc_make_safe_expr copies them
into temporaries, and never makes the start safe, so the loops use the
variables themselves.  Found with the Fujitsu test suite (0246_0055).

Reply via email to