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

    <tr>
        <th>Summary</th>
        <td>
            [Flang][OpenMP] Compilation errors in DO SIMD construct with FIRSTPRIVATE clause
        </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 : 22.0.0(5892a2beec4eaf77922211a9aec70faa0ae287db)/AArch64
```

Specifying `FIRSTPRIVATE` clause in `DO SIMD` construct results in a compilation error (`FIRSTPRIVATE cannot be used with SIMD`).

According to `OpenMP 6.0: 12.4 simd Construct` and `OpenMP 6.0: 13.6.2 do Construct`,
- `FIRSTPRIVATE` clause cannot be specified in `SIMD` construct.
- `FIRSTPRIVATE` clause can be specified in `DO` construct.

Also, according to `OpenMP 6.0: 19.2 Clauses on Compound Constructs`,
- `!$omp do simd` is `Compound Construct` that combines `DO` construct (`worksharing construct`) and `SIMD` construct.
- `DO` construct is `worksharing construct` and `FIRSTPRIVATE` clause is applied.
- `SIMD` construct is not a `worksharing construct`, so `FIRSTPRIVATE` clause is not applied.

So it seems likely that `FIRSTPRIVATE` clause can be specified in `DO SIMD` construct, which is `Compound Construct`.  
Thus, the Flang compilation error messages appear to violate the OpenMP specification.  
Please point out any errors in my interpretation of OpenMP.


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

test01.f90:
```fortran
subroutine sub
  integer a
  a=10
!$omp do simd lastprivate(a) firstprivate(a)
  do i=1,1
     if (a/=10) print *,11
     a=20
  end do
!$omp end do simd
  if (a/=20) print *,21
end subroutine sub

program main
  integer a
  a=10
!$omp do simd lastprivate(a) firstprivate(a)
  do i=1,1
     if (a/=10) print *,11
     a=20
  end do
!$omp end do simd
  if (a/=20) print *,21
  call sub
  print *,'pass'
end program main
```

```
$ flang -fopenmp test01.f90
error: loc("/work/home/ohno/CT/test/fort/tp/reproducerJ/FJ-Compiler-Test-Suite/34/test01.f90":4:7): FIRSTPRIVATE cannot be used with SIMD
error: loc("/work/home/ohno/CT/test/fort/tp/reproducerJ/FJ-Compiler-Test-Suite/34/test01.f90":16:7): FIRSTPRIVATE cannot be used with SIMD
error: verification of lowering to FIR failed
$
```

```
$ gfortran -fopenmp test01.f90
test01.f90:4:44:

    4 | !$omp do simd lastprivate(a) firstprivate(a)
      |                                            ^
Error: firstprivate variable ‘a’ is private in outer context
test01.f90:4:44: Error: lastprivate variable ‘a’ is private in outer context
test01.f90:16:44:

   16 | !$omp do simd lastprivate(a) firstprivate(a)
      |                                            ^
Error: firstprivate variable ‘a’ is private in outer context
test01.f90:16:44: Error: lastprivate variable ‘a’ is private in outer context
$
```

```
$ export OMP_NUM_THREADS=2; ifx -qopenmp test01.f90; ./a.out
 pass
$
```

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzkV29v4rgT_jTmzYjIDATIC16k0Px-XanXqu3t25VJJuDdEOdsp3--_Wmc0EJpu3u3K510hyqVxPYzzzwzfmyUc3pTEy1EfCbi1UC1fmvswmxrMyy_DtameFqIqez_ZPqZrNOmBlNCWal6A2KcAmIkIylwHs8TVLgmyiekytksQcTRSCWK8pkslZKKcD4r1gITgVma2nw7nQiZHkYQMr1tKNflk2b4qcwubm7vrm8uPqd352IqIa9U6wh0zYOrK7i9uFyF96Z23ra5B0uurbzjKQpys2t0pTyzJmuNBYHzV7CQq7o2HtYEraMCHrTf7nEFJlFHK81zYwtm5Q3HvmqovryGaSRZhBFGE3B6V8ByT4RZqbp4Y-44mkYIhTmaK3ApZDr8IOcXmi5IpKnodTgRIfo-1Fs4q6sTFM68ckbgEtTHCiQRwjLAOzA1LM2uMW19IIg7zlLgSODE7BpWgqXj2Nrx0OlaHvNb5bmga12Te4NuX9oHY7-5rbJMND8SONnX4329XkN2fN6D3OO916QOV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