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

    <tr>
        <th>Summary</th>
        <td>
            [Flang][OpenMP] Compilation error of the update-statement of `atomic` constructs
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    This is an issue from Fujitsu testsuite.

Flang-new terminates abnormally when compiling atomic constructs.
I couldn't find the minimal conditions to reproduce this issue.

The following are the test program, Flang-new and gfortran compilation result.


```fortran
! test.f90
integer(kind=4) :: iaa
integer(kind=4) :: ibb
integer(kind=4) :: icc
iaa=1
ibb=1
icc=1

!$OMP atomic
iaa=(1+ibb*2)+iaa ! flang-new fails
! $OMP atomic
!iaa=+icc*ibb*2*iaa ! gfortran/ifort fails

end
```
```console
$ flang-new -v test.f90 -fopenmp
flang-new version 17.0.0 (https://github.com/llvm/llvm-project.git e126fa27c07c83997fcdee2bd45996ffc860317b)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/install/bin
Found candidate GCC installation: /opt/rh/gcc-toolset-10/root/usr/lib/gcc/aarch64-redhat-linux/10
Selected GCC installation: /opt/rh/gcc-toolset-10/root/usr/lib/gcc/aarch64-redhat-linux/10
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/path/to/install/bin/flang-new" -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -fopenmp -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +neon -target-feature +v8a -o /tmp/test-b64af8.o -x f95-cpp-input test.f90
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /path/to/install/bin/flang-new -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -fopenmp -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +neon -target-feature +v8a -o /tmp/test-b64af8.o -x f95-cpp-input test.f90
 #0 0x0000ffffa5d40900 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/path/to/install/bin/../lib/libLLVMSupport.so.17git+0x1a0900)
 #1 0x0000ffffa5d3e9e0 llvm::sys::RunSignalHandlers() (/path/to/install/bin/../lib/libLLVMSupport.so.17git+0x19e9e0)
 #2 0x0000ffffa5d3eb50 SignalHandler(int) Signals.cpp:0:0
 #3 0x0000ffffa78007a0 (linux-vdso.so.1+0x7a0)
 #4 0x0000ffff9d8831fc llvm::OpenMPIRBuilder::emitAtomicUpdate(llvm::IRBuilderBase::InsertPoint, llvm::Value*, llvm::Type*, llvm::Value*, llvm::AtomicOrdering, llvm::AtomicRMWInst::BinOp, llvm::function_ref<llvm::Value* (llvm::Value*, llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>&)> const&, bool, bool) (/path/to/install/bin/../lib/../lib/libLLVMFrontendOpenMP.so.17git+0x431fc)
 #5 0x0000ffff9d894600 llvm::OpenMPIRBuilder::createAtomicUpdate(llvm::OpenMPIRBuilder::LocationDescription const&, llvm::IRBuilderBase::InsertPoint, llvm::OpenMPIRBuilder::AtomicOpValue&, llvm::Value*, llvm::AtomicOrdering, llvm::AtomicRMWInst::BinOp, llvm::function_ref<llvm::Value* (llvm::Value*, llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>&)> const&, bool) (/path/to/install/bin/../lib/../lib/libLLVMFrontendOpenMP.so.17git+0x54600)
 #6 0x0000ffff99f0204c convertOmpAtomicUpdate(mlir::omp::AtomicUpdateOp&, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) OpenMPToLLVMIRTranslation.cpp:0:0
 #7 0x0000ffff99f0c93c (anonymous namespace)::OpenMPDialectLLVMIRTranslationInterface::convertOperation(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) const OpenMPToLLVMIRTranslation.cpp:0:0
 #8 0x0000ffff9da71114 mlir::LLVM::ModuleTranslation::convertOperation(mlir::Operation&, llvm::IRBuilderBase&) (/path/to/install/bin/../lib/../lib/libMLIRTargetLLVMIRExport.so.17git+0x21114)
 #9 0x0000ffff9da7c394 mlir::LLVM::ModuleTranslation::convertBlock(mlir::Block&, bool, llvm::IRBuilderBase&) (/path/to/install/bin/../lib/../lib/libMLIRTargetLLVMIRExport.so.17git+0x2c394)
#10 0x0000ffff9da7f044 mlir::LLVM::ModuleTranslation::convertOneFunction(mlir::LLVM::LLVMFuncOp) (/path/to/install/bin/../lib/../lib/libMLIRTargetLLVMIRExport.so.17git+0x2f044)
#11 0x0000ffff9da7f694 mlir::LLVM::ModuleTranslation::convertFunctions() (/path/to/install/bin/../lib/../lib/libMLIRTargetLLVMIRExport.so.17git+0x2f694)
#12 0x0000ffff9da7fdfc mlir::translateModuleToLLVMIR(mlir::Operation*, llvm::LLVMContext&, llvm::StringRef) (/path/to/install/bin/../lib/../lib/libMLIRTargetLLVMIRExport.so.17git+0x2fdfc)
#13 0x0000ffffa6a17b4c Fortran::frontend::CodeGenAction::generateLLVMIR() (/path/to/install/bin/../lib/libflangFrontend.so.17git+0x117b4c)
#14 0x0000ffffa6a1963c Fortran::frontend::CodeGenAction::executeAction() (/path/to/install/bin/../lib/libflangFrontend.so.17git+0x11963c)
#15 0x0000ffffa695047c Fortran::frontend::FrontendAction::execute() (/path/to/install/bin/../lib/libflangFrontend.so.17git+0x5047c)
#16 0x0000ffffa6943334 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/path/to/install/bin/../lib/libflangFrontend.so.17git+0x43334)
#17 0x0000ffffa6ea30a8 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/path/to/install/bin/../lib/libflangFrontendTool.so.17git+0x30a8)
#18 0x0000000000404870 fc1_main(llvm::ArrayRef<char const*>, char const*) (/path/to/install/bin/flang-new+0x404870)
#19 0x0000000000403104 main (/path/to/install/bin/flang-new+0x403104)
#20 0x0000ffffa5710de4 __libc_start_main (/lib64/libc.so.6+0x20de4)
#21 0x00000000004035d0 _start (/path/to/install/bin/flang-new+0x4035d0)
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 17.0.0 (https://github.com/llvm/llvm-project.git e126fa27c07c83997fcdee2bd45996ffc860317b)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/install/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/test-e5acc3
flang-new: note: diagnostic msg: /tmp/test-e5acc3.sh
flang-new: note: diagnostic msg: 

********************
```
```console
$ gfortran -v test.f90 -fopenmp
Driving: gfortran -v test.f90 -fopenmp -l gfortran -l m -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-redhat-linux/8/lto-wrapper
Target: aarch64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-gnu-indirect-function --build=aarch64-redhat-linux
Thread model: posix
gcc version 8.4.1 20200928 (Red Hat 8.4.1-1) (GCC) 
 :
$
```

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