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

            Bug ID: 110718
           Summary: [OpenMP] Wrong value for 'lastprivate' for zero-trip
                    loops
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: openmp, wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: jakub at gcc dot gnu.org
  Target Milestone: ---

In Fortran, a loop
  do i = m1, m2, m3
has a zero-trip loop if  '(m2 - m1 + m3)/m3' <= 0 (the LHS is how the loop
count is calculated).

The second step for the loop initialization is:
"(2) The DO variable becomes defined with the value of the initial parameter
m1."

(For both, see e.g. F2023, "11.1.7.4.1 Loop initiation".)

Hence, the expected value of 'i' after a zero-trip loop is m1.

However, with OpenMP, this fails with zero-trip loops - having some odd value.
(The equivalent C program works.)

Example: The following program prints "-2" (instead of 3 [= n])
and, hence, fails then with "STOP 2".

implicit none
integer :: i, n, m

n = 3
m = 10
i = 99
!$omp parallel do lastprivate(i)
do i = n,m,-2
  stop 1 ! should not run
end do
print *, i
if (i /= 3) stop 2
end

Reply via email to