<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/64270>64270</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [flang] [OpenMP] [hlfir] inconsistent result (libgomp/testsuite/libgomp.fortran/pr46753.f90)
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          k-arrows
      </td>
    </tr>
</table>

<pre>
    Consider the following program:
https://github.com/gcc-mirror/gcc/blob/master/libgomp/testsuite/libgomp.fortran/pr46753.f90
```console
$ cat pr46753.f90
! PR fortran/46753
! { dg-do run }

  integer :: i, j
  j = 0
!$omp parallel do reduction(+:j)
  do i = 2147483636, 2147483646
    j = j + 1
  end do
  if (j.ne.11) stop 1
  j = 0
!$omp parallel do reduction(+:j)
  do i = -2147483637, -2147483647, -1
    j = j + 1
  end do
  if (j.ne.11) stop 2
end
```

Compilation and execution results:
```console
$ flang-new -fopenmp -flang-experimental-hlfir pr46753.f90
$ ./a.out
Fortran STOP: code 2

IEEE arithmetic exceptions signaled: INEXACT
```

If you change the program to display the value of the variable `j` at the location of the STOP statement, you get the following inconsistent result:
```console
$ ./a.out
 11
 6
$ ./a.out
 11
 7
$ ./a.out
 11
 10
$ ./a.out
 11
 6
$ ./a.out
 11
 8
$ ./a.out
 11
 11
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVc2OozgQfhpzKYGw-QsHDkmnkfqwO63dOezVmII4a2xkm-nut18Zks6qd2aUHbUUEb6qon6_srlzctSIDSkOpDhGfPEnY5u_Y26teXFRZ_q35sFoJ3u04E8Ig1HKvEg9wmzNaPlEsj1JjyTdn7yfXUCsJawdpT8tXSLMFIAQ8SStNXYDhLWdMh1h7cSdxyBVshvNNBPWenTeLdLjTZoMxnrLNWHtbPOyKrJkqNMtLCnT7SeMdkbhRcpyENzDf80Zhec_4OZw1d90pDpAP8a9AbtoINXxolqfAFJ7HNFCqDPbgyTsAc5X5RlIdoRbIMJyM80wc8uVQgXBKfaL8NJownaEHUi2PxNWXx30BuTqg9G8yndZmZUhwBXl5dXwGusMhB2AXsWoe-jNe64DELY7JxoTSgmrwXkz34w_L9v4Pd0qpPsO8w3ST8iabWrU_Yep_3s8D2aapeIhYeC6B3xFsazIoluUd-9c_TFpBsX1GGt8gXgwM-pphniT4euMVk6oPVfxSQ3Sfo9dOSSEtTwxi99E7cY0-PPrl-dAGWF6vJazPZ8eHx-BW-lPE3opAF8FziFtB2E7ucI-fPj0--Nf-4evP6n_aYA3s4A4cT3iuq2XHQVvoJduVvxtFX_jakEwwwVYyTuFQMr0TMoUuF_lyoitlRe7UAA4zz2GHoTJhmAj-g_ngtShqdJ51P7S-Dv6_qFrQK_0KO-wqe6woT8e0f8LtrsnGP1Qb9Q3WV9nNY-woWWd7tKaFml0amqW0nKgVdZVdVHkFRUVq3helRTrPivzSDYsZVlaZZRmlLEyEaUo010hyjyr-cAqkqc4cakSpb5NibFjJJ1bsClzVqWR4h0qt57vjAVar0rCWDjubRO-ibtldCRPlXTe3bx46dV6Maz0J8URSHH4MqP-7fkC1iUI798ZeVjiXznTWR0tVjU_uUxCgpe_eLbmjMIT1q5lOcLatex_AgAA__8xN_DW">