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

    <tr>
        <th>Summary</th>
        <td>
            [Flang][OpenMP] Incorrect execution result of a variable in critical construct in parallel construct with default(firstprivate) clause
        </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 : 18.0.0(76bbbcb41bcf4a1d7a26bb11b78cf97b60ea7d4b)
```

The execution result of a variable in `critical` construct in `parallel` construct with `default(firstprivate)` clause is incorrect.  
The execution result is correct if:
- remove `critical` construct, or
- change `default(firstprivate)` to `firstprivate(j)`


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

snf_ng_01_1.f90:
```fortran
program main
  INTEGER :: j
  j=2
!$OMP PARALLEL default(firstprivate)
!$OMP critical
 j=200
!$OMP END critical
!$OMP END PARALLEL
  if (j.ne.2) print *,'err var j=',j
  print *,'pass'
end program main
```

```
$ export OMP_NUM_THREADS=2; flang-new -fopenmp snf_ng_01_1.f90; ./a.out
 err var j= 200
 pass
$
```

```
$ export OMP_NUM_THREADS=2; gfortran -fopenmp snf_ng_01_1.f90; ./a.out
 pass
$
```

```
$ export OMP_NUM_THREADS=2; ifort -qopenmp snf_ng_01_1.f90; ./a.out
 pass
$
```

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