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

    <tr>
        <th>Summary</th>
        <td>
            [Flang][OpenMP] Execution does not terminate when the same variable is specified for firstprivate and lastprivate clause in sections construct
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            openmp,
            flang
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          ohno-fj
      </td>
    </tr>
</table>

<pre>
    ```
Version of flang-new : 19.0.0(cbcdf126ccc774c063b5d5140c1393ff5305dded)/AArch64
```

If the same variable is specified for `firstprivate` and `lastprivate` clause in `sections` construct, the execution does not terminate after about an hour.
Gfortran/ifort completes in less than one second.

If only one of `firstprivate` and `lastprivate` clause is specified, the execution terminates normally.

The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.

omp_PL_SECTIONS_004r_2.f:
```fortran
      program main
      real*4 ra
      integer*4 ib(10), ic , it, ier
 integer*4 :: loop=10, loop2=20000, thread=4
!$    integer*4 OMP_GET_MAX_THREADS
!$    integer*4 OMP_GET_THREAD_NUM
      ra = 15.
      ib = 0
!$    thread = OMP_GET_MAX_THREADS()
!$omp parallel private(it)
!$    it = OMP_GET_THREAD_NUM() + 1
!$omp sections firstprivate(ra) lastprivate(ra)
      ib(it)=ib(it)+it
      do i=1,loop2
         ra=ra+it
      enddo
      ra=loop2*1
!$omp end sections
!$omp end parallel
      end
```

```
$ export OMP_NUM_THREADS=2; flang-new -fopenmp omp_PL_SECTIONS_004r_2.f; time ./a.out
  C-c C-c
real    77m46.270s
user    0m0.378s
sys 0m0.040s
$
```

```
$ export OMP_NUM_THREADS=2; gfortran -fopenmp omp_PL_SECTIONS_004r_2.f; time ./a.out

real 0m0.036s
user    0m0.000s
sys     0m0.015s
$
```

```
$ export OMP_NUM_THREADS=2; ifort -qopenmp -diag-disable=10448 omp_PL_SECTIONS_004r_2.f; time ./a.out

real    0m0.070s
user 0m0.006s
sys     0m0.029s
$
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VlGT2yYQ_jX4hbEGgSRbD36wrXOamV6SaS6dvnmQWNlkEKiAcrl_3wHZPtl3vSbt9OZsmV3t7vd9wAJ3Th40wArlG5RXMz74o7Erc9Rm3n6d1UY8rVBBTv-kQmT9O1gnjcamxa3i-jDX8IgRW-O0TEhCEF02dSPalBZN0ywWWUMKVuciTzPSpKxkbZszkgsBAtES0d16bZtjkY3Jb2qN3-9b7I-AHe8Af-NW8loBlg67HhrZShC4NRajgrTSOt9b-Y17QAXBXItgVvzK2ig-OMBSB5-DxkujXXQY7bwdGo_oNlaE79AMwY2FAYe18diD7aTmHjBvPVjMazN4zDU-msEmI953rbHeco3oToafuDFdr8CDC0UVOIf9kWtsNGAHjdEiuaFrtHqKbtP-PK-JMC-JXPAHOrbjSj1dFX84Am6NUuZR6gPmFmK8B-dxb83B8i7k3J0nPgzOdCOsZ8JS8VAR0d1zdQtuUP6qoOn6_adf95_vtg_vP374vCcks3uatIitb5bEWdVoxfHvBAl3XF7ZLXCF6DrDlk_NUns4gI0eWSO6TElcg1ssGxwfceol2FPUNCAAYmusjOkRq0LkNg4oYhUlhJBRbAtcIFad1zNNEc1ua3-8_7R_d_ewv1__sX_45be7dfX5R14fX91_-HJ_xZVjxCqc5skV1TpayW3eEWD0vYaCLoMgkxjT9bjnlisFCp8XG10GocoXmP1V3gncmBYjusHpbfLzBsRXi5wuLQ8h0yV-sl2zvGBh1WRAN9JP3xMGyzBpiG7HKZv4ooSIVSH5TRhoIcy11ohVYwa6fkEFtLjQec131vGmxBud79ZIMwzf-7DDgsgfvtxfJo5VFLHNpCPPW9OD7nr89xtsg73sACeI7nhihgv17bwJn3EYtlIAulh0WZHQBTlRGxzYYCcdSdhiebK6JxctJCMXCd5q7T9N8HBuNv-a34RWRMqKVxgRQiaMLtY0_39YjV1z_ueJ0lxIfpgL6c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