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

    <tr>
        <th>Summary</th>
        <td>
            [Flang][OpenMP] Compilation error for statement in atomic construct
        </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 : 19.0.0(00efb343529cce025055ca8284a61b22b48924c9)/AArch64
```

The compilation is an error if `statement` in `atomic` construct is:
- operation of integer (kind=1) variable, or (omp_atomic_001_2.f90)
- operation of integer (kind=2) variable, or (omp_atomic_002_2.f90)
- operation of integer(kind=4) and integer(kind=8), or  (omp_atomic_003_2.f90)
- operation of integer(kind=8) and real(kind=8), or     (omp_atomic_004_2.f90)
- operation of real(kind=4) and real(kind=8), or        (omp_atomic_005_2.f90)
- operation of real(kind=8) and real(kind=16) (omp_atomic_006_2.f90)

The above conditions result in the same error. 
Each program is attached at the end.

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

omp_atomic_001_2.f90:
```fortran
program main
 integer(1)::i1=5

!$omp parallel
!$omp atomic
  i1=i1+1
!$omp atomic
  i1=i1-1
!$omp end parallel

end program main
```

```
$ flang-new -fopenmp omp_atomic_001_2.f90
error: loc("/work/home/ohno/CT/test/fort/tp/reproducerJ/fomp_omp30/omp_atomic_001_2.f90":1:1): no atomic update operation with region argument as operand found inside atomic.update region
error: loc("/work/home/ohno/CT/test/fort/tp/reproducerJ/fomp_omp30/omp_atomic_001_2.f90":1:1): LLVM Translation failed for operation: omp.atomic.update
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /lustre/home/ohno/LLVM_20240307/release/bin/flang-new -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -fopenmp -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +outline-atomics -target-feature +v8a -target-feature +fp-armv8 -target-feature +neon -mframe-pointer=non-leaf -o /tmp/omp_atomic_001_2-3539fb.o -x f95-cpp-input omp_atomic_001_2.f90
 #0 0x00000000040dc3d8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lustre/home/ohno/LLVM_20240307/release/bin/flang-new+0x40dc3d8)
 #1 0x00000000040da2e0 llvm::sys::RunSignalHandlers() (/lustre/home/ohno/LLVM_20240307/release/bin/flang-new+0x40da2e0)
 #2 0x00000000040da464 SignalHandler(int) Signals.cpp:0:0
 #3 0x0000400005c607a0 (linux-vdso.so.1+0x7a0)
 #4 0x0000000007467644 llvm::CodeExtractor::findAllocas(llvm::CodeExtractorAnalysisCache const&, llvm::SetVector<llvm::Value*, llvm::SmallVector<llvm::Value*, 0u>, llvm::DenseSet<llvm::Value*, llvm::DenseMapInfo<llvm::Value*, void>>, 0u>&, llvm::SetVector<llvm::Value*, llvm::SmallVector<llvm::Value*, 0u>, llvm::DenseSet<llvm::Value*, llvm::DenseMapInfo<llvm::Value*, void>>, 0u>&, llvm::BasicBlock*&) const (/lustre/home/ohno/LLVM_20240307/release/bin/flang-new+0x7467644)
 #5 0x0000000007088810 llvm::OpenMPIRBuilder::createParallel(llvm::OpenMPIRBuilder::LocationDescription const&, llvm::IRBuilderBase::InsertPoint, llvm::function_ref<void (llvm::IRBuilderBase::InsertPoint, llvm::IRBuilderBase::InsertPoint)>, llvm::function_ref<llvm::IRBuilderBase::InsertPoint (llvm::IRBuilderBase::InsertPoint, llvm::IRBuilderBase::InsertPoint, llvm::Value&, llvm::Value&, llvm::Value*&)>, std::function<void (llvm::IRBuilderBase::InsertPoint)>, llvm::Value*, llvm::Value*, llvm::omp::ProcBindKind, bool) (/lustre/home/ohno/LLVM_20240307/release/bin/flang-new+0x7088810)
 #6 0x000000000579bd40 (anonymous namespace)::OpenMPDialectLLVMIRTranslationInterface::convertOperation(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) const OpenMPToLLVMIRTranslation.cpp:0:0
 #7 0x0000000005e2b420 mlir::LLVM::ModuleTranslation::convertOperation(mlir::Operation&, llvm::IRBuilderBase&, bool) (/lustre/home/ohno/LLVM_20240307/release/bin/flang-new+0x5e2b420)
 #8 0x0000000005e34274 mlir::LLVM::ModuleTranslation::convertBlockImpl(mlir::Block&, bool, llvm::IRBuilderBase&, bool) (/lustre/home/ohno/LLVM_20240307/release/bin/flang-new+0x5e34274)
 #9 0x0000000005e34f20 mlir::LLVM::ModuleTranslation::convertOneFunction(mlir::LLVM::LLVMFuncOp) (/lustre/home/ohno/LLVM_20240307/release/bin/flang-new+0x5e34f20)
#10 0x0000000005e358f0 mlir::LLVM::ModuleTranslation::convertFunctions() (/lustre/home/ohno/LLVM_20240307/release/bin/flang-new+0x5e358f0)
#11 0x0000000005e3a2cc mlir::translateModuleToLLVMIR(mlir::Operation*, llvm::LLVMContext&, llvm::StringRef) (/lustre/home/ohno/LLVM_20240307/release/bin/flang-new+0x5e3a2cc)
#12 0x000000000472db08 Fortran::frontend::CodeGenAction::generateLLVMIR() (/lustre/home/ohno/LLVM_20240307/release/bin/flang-new+0x472db08)
#13 0x000000000472fcc8 Fortran::frontend::CodeGenAction::executeAction() (/lustre/home/ohno/LLVM_20240307/release/bin/flang-new+0x472fcc8)
#14 0x00000000041112fc Fortran::frontend::FrontendAction::execute() (/lustre/home/ohno/LLVM_20240307/release/bin/flang-new+0x41112fc)
#15 0x0000000004105b6c Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/lustre/home/ohno/LLVM_20240307/release/bin/flang-new+0x4105b6c)
#16 0x0000000004115f78 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/lustre/home/ohno/LLVM_20240307/release/bin/flang-new+0x4115f78)
#17 0x0000000003d2e4a8 fc1_main(llvm::ArrayRef<char const*>, char const*) (/lustre/home/ohno/LLVM_20240307/release/bin/flang-new+0x3d2e4a8)
#18 0x0000000003cb6890 main (/lustre/home/ohno/LLVM_20240307/release/bin/flang-new+0x3cb6890)
#19 0x00004000060f4384 __libc_start_main (/lib64/libc.so.6+0x24384)
#20 0x0000000003d2d32c _start (/lustre/home/ohno/LLVM_20240307/release/bin/flang-new+0x3d2d32c)
flang-new: error: unable to execute command: Segmentation fault (core dumped)
flang-new: error: flang frontend command failed due to signal (use -v to see invocation)
flang-new version 19.0.0git (https://github.com/llvm/llvm-project.git 00efb343529cce025055ca8284a61b22b48924c9)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /lustre/home/ohno/LLVM_20240307/release/bin
flang-new: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
flang-new: note: diagnostic msg: /tmp/omp_atomic_001_2-6d2762
flang-new: note: diagnostic msg: /tmp/omp_atomic_001_2-6d2762.sh
flang-new: note: diagnostic msg:

********************
$
```

```
$ cat /tmp/omp_atomic_001_2-6d2762
#line "./omp_atomic_001_2.f90" 1
 program main
      integer(1)::i1=5

!$omp parallel
!$omp atomic
      i1=i1+1
!$omp atomic
      i1=i1-1
!$omp end parallel

      end program main
$
```

```
$ cat /tmp/omp_atomic_001_2-6d2762.sh
# Crash reproducer for clang version 19.0.0git (https://github.com/llvm/llvm-project.git 00efb343529cce025055ca8284a61b22b48924c9)
# Driver args: "-fopenmp" "omp_atomic_001_2.f90"
# Original command: "/lustre/home/ohno/LLVM_20240307/release/bin/flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu" "-emit-obj" "-fopenmp" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-target-cpu" "generic" "-target-feature" "+outline-atomics" "-target-feature" "+v8a" "-target-feature" "+fp-armv8" "-target-feature" "+neon" "-mframe-pointer=non-leaf" "-o" "/tmp/omp_atomic_001_2-3539fb.o" "-x" "f95-cpp-input" "omp_atomic_001_2.f90"
 "/lustre/home/ohno/LLVM_20240307/release/bin/flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu" "-emit-obj" "-fopenmp" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-target-cpu" "generic" "-target-feature" "+outline-atomics" "-target-feature" "+v8a" "-target-feature" "+fp-armv8" "-target-feature" "+neon" "-mframe-pointer=non-leaf" "-x" "f95-cpp-input" "omp_atomic_001_2-6d2762"
$
```

```
$ export OMP_NUM_THREADS=2; gfortran -fopenmp omp_atomic_001_2.f90; ./a.out
 i1 =     5
$
```

```
$ export OMP_NUM_THREADS=2; ifort -qopenmp -diag-disable=10448 omp_atomic_001_2.f90; ./a.out
 i1 = 5

$
```

omp_atomic_002_2.f90:
```fortran
program main
  integer(2)::i2=5

!$omp parallel
!$omp atomic
 i2=i2+1
!$omp atomic
  i2=i2-1
!$omp end parallel

end program main
```

omp_atomic_003_2.f90:
```fortran
program main
 integer(4)::i4=5
  integer(8)::a=10

!$omp parallel
!$omp atomic
  i4=i4+a
!$omp end parallel

end program main
```

omp_atomic_004_2.f90:
```fortran
program main
 integer(8)::i8=5
  real(8)::a=10

!$omp parallel
!$omp atomic
 i8=i8+a
!$omp end parallel

end program main
```

omp_atomic_005_2.f90:
```fortran
program main
 real(4)::r4=5
  real(8)::a=10

!$omp parallel
!$omp atomic
 r4=r4+a
!$omp end parallel

end program main
```

omp_atomic_006_2.f90:
```fortran
program main
 real(8)::r8=5
  real(16)::a=10

!$omp parallel
!$omp atomic
 r8=r8+a
!$omp end parallel

end program main
```

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