[Flang][OpenMP] Compilation error for atomic capture with array elements
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
## Summary
According to the OpenMP 6.0 specification, the following program should be valid. However, a verification error occurs.
* 6.3.3 OpenMP Atomic Structured Blocks
> A write structured block is *write-statement*, a write statement that has one of the following forms:
>> x = expr
>> x => expr
> A capture structured block has one of the following forms:
>> statement
>> capture-statement
>
> or
>> capture-statement
>> statement
>
> where *capture-statement* has either of the following forms:
>> v = x
>> v => x
>
> If *statement* is *write-statement* as specified above then it is a write-capture structured block.
### Reproducer
* test.f90
```fortran
integer(1)::p(2)
integer(4)::j(1)
j=100
p=0
!$omp atomic capture
p(1)=max(p(2),2) ! write statement
j(1)=p(1) ! capture statement
!$omp end atomic
if(j(1)/=2) print *,'err'
print *,'pass'
end
```
* commands
```console
$ flang --version
flang version 23.0.0git (https://github.com/llvm/llvm-project.git 3e20d3d3964a3a6ac5f882842c7716e2682d622f)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/llvm/build/bin
Build config: +assertions
$ flang test.f90 -fopenmp && ./a.out
error: loc("/path/to/test.f90":5:7): invalid sequence of operations in the capture region
error: verification of lowering to FIR failed
```
## Other Compilers
* GFortran
```console
$ gfortran --version
GNU Fortran (GCC) 15.2.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gfortran test.f90 -fopenmp && ./a.out
pass
```
* Intel Fortran
```console
$ ifx --version
ifx (IFX) 2025.3.2 20260112
Copyright (C) 1985-2026 Intel Corporation. All rights reserved.
$ ifx -O0 test.f90 -qopenmp
$ pass
```
Contributor guide
Assessment
This issue has not been assessed yet.