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

    <tr>
        <th>Summary</th>
        <td>
            [Flang][OpenMP] Incorrect execution result of a firstprivate variable in parallel construct
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            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 : 18.0.0(770dc47659d41a5ca7b7daf5b3134c900ca8c33d)
```
The value of a `firstprivate` variable (`a`) in `parallel` construct executed by each thread is incorrect.

The following `write` statement expects that the value of variable (`a`) is 200 for all threads.
```
  write(6,*) "2 : a = ", a
```

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

sngf_firstprivate11_42.f90:
```fortran
subroutine sub4()
  integer :: a = 100
!$omp parallel reduction(max:a)
  a = 200
!$omp parallel firstprivate(a)
  if (a/=200) print *,14,a
  a = 300
!$omp end parallel
  write(6,*) "2 : a = ", a
  if (a/=200) print *,24,a
  a = 400
!$omp end parallel
  write(6,*) "3 : a = ", a
end subroutine sub4

program main
  call sub4
end program main
```

```
$ export OMP_NUM_THREADS=2; flang-new -fopenmp sngf_firstprivate11_42.f90; ./a.out
 2 : a =  200
 2 : a =  400
 24 400
 3 : a =  400
$
```

```
$ export OMP_NUM_THREADS=2; gfortran -fopenmp sngf_firstprivate11_42.f90; ./a.out
 2 : a = 200
 2 : a =          200
 3 : a = 400
$
```

```
$ export OMP_NUM_THREADS=2; ifort -qopenmp sngf_firstprivate11_42.f90; ./a.out
 2 : a =          200
 2 : a = 200
 3 : a =          400
$
```


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VU9v47YT_TT0ZWCBGlKSdfDBiX_-tYd0F-2214CiKJkLilRJKtn99gVlO3YcZ1t0t4YBgcT8eW_mcUaEoHur1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