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

    <tr>
        <th>Summary</th>
        <td>
            [Flang][OpenMP] Variable in parallel sections construct with default(private) clause is not treated as private
        </td>
    </tr>

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

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

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

<pre>
    ```
Version of flang : 21.0.0(fb86b3d96b73f4e628288b180ef4e038da8b7bc1)/AArch64
```

sngf_reduction71_222.f90:
```fortran
program main
  integer a
  a=10
!$omp parallel sections default(private)
 a=15
!$omp end parallel sections
  print *,'a = ', a
end program main
```

`Variable (a)` in `parallel sections construct` with `default (private) clause` is not treated as `private`.  
After `parallel sections construct` ends, the value of `variable (a)` is expected to be 10.

I found `variable (a)` is treated as `private` in the following cases:
- `default (private) clause` is changed to `private (a) clause`
   See sngf_reduction71_232.f90 below.
- `parallel sections construct` is changed to `parallel construct`
   See sngf_reduction71_223.f90 below.

The following are the test program, Flang, Gfortran and ifx compilation/execution result.


```
$ export OMP_NUM_THREADS=2; flang -fopenmp sngf_reduction71_222.f90; ./a.out
flang-21: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
 a =  15
$
```

```
$ export OMP_NUM_THREADS=2; gfortran -fopenmp sngf_reduction71_222.f90; ./a.out
 a =           10
$
```

```
$ export OMP_NUM_THREADS=2; ifx -qopenmp sngf_reduction71_222.f90; ./a.out
 a = 10
$
```

sngf_reduction71_232.f90:
```fortran
program main
  integer a
  a=10
!$omp parallel sections private(a)
  a=15
!$omp end parallel sections
  print *,'a = ', a
end program main
```

```
$ export OMP_NUM_THREADS=2; flang -fopenmp sngf_reduction71_232.f90; ./a.out
flang-21: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
 a = 10
$
```

sngf_reduction71_223.f90:
```fortran
program main
  integer a
  a=10
!$omp parallel default(private)
  a=15
!$omp end parallel
 print *,'a = ', a
end program main
```

```
$ export OMP_NUM_THREADS=2; flang -fopenmp sngf_reduction71_223.f90; ./a.out
flang-21: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
 a = 10
$
```


</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMVs1y2zYQfprVZUccEPwRdeCBjqq2hzSZJk2PHpBcUshAAAuAdvr2HUCUY8dyErdNG41mBGh29_v2Fyuck6MmqqG4gmK3ErM_GFubgzbr4f2qNf2fNZRs-bLmHVknjUYz4KCEHhGyBnmasIQBr4a2Ktus35btJhtyKnnFq6pNK0ZDTiyrelG1m7ZLgW-B75vGdocyB9bcRwDWOD0O15b6ufPS6E16zTlPhi2DrLkvPBjrrdDAmsma0YojHoUMV0SpPY1kUcSbgGyXRts8BZ6b44STsEIpUugogjjsaRCz8sCrycob4SmQZM1JuXigTLp_bCAiTVZqj8Ab4C-AbwRCtkPgG-AvIpeo-ZDsJ75Dyd4JK0WrCIFXIrAoGUqNULLHrDujnbdz54PQrfSHILa4gg98wU6J2VE05lAbj96S8NSjcNH2IlmyBBFY0wye7FeAku5dcM8fCG-EminUBpTs5pIXDunDRF1A9QZbwpQlJ79_xsHMuv-M5lN0Q2wC-GCUMrdSj9gJR-5ULOuvjEd3EHo8sfpo_Ezgo2hMMr4hwsc1msUaxZaUuU3O0F8I3mPks_x9sc-h8uwhKrDm7YNgCEsxPJ6cP9deyNc-tG84_Lj0EQrdoxw-YGeOk1QiIADf0wfq5nBGS25WfgH5tHJ5HlJrrMdXL19f__Lby-u3P_36Q7N7A9mOQ3a1jIv1YCbSx-mSJ0uPX2ECfC8SM3tgTVRb8zTMmVthtdRjOL6aSL98jW6eIqbUi33p0HmpVKwzK4-kvVAIxdX69_v_rM0U3St2scVjm-LS5RcG0vM8Hc8BfbazZyZ3n2Vq_WNKIa3rP_4em6c5PNUD33RO33XwaTbc6f2nI_rfrPvsf6775-T3N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