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

    <tr>
        <th>Summary</th>
        <td>
            [Flang][OpenMP] Compilation error when the same type (complex) is used in capture-statement in atomic read 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(fdcdc3d759224f0ec0a3e472f7940d4b0f3a1b79)/AArch64
```

In [#93441](https://github.com/llvm/llvm-project/issues/93441), when a different `type` is used in `capture-statement` in `atomic read` construct, the compilation terminates abnormally.  
However, when the same `type (complex)` is used, the compilation also terminates abnormally.

Compilation ends normally in the following cases:
- change `complex` to `real`, or
- change `complex` to `integer`

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

OMP_3_O_007_4_atm_type_140_re_.f90:
```fortran
subroutine sub2()
  complex(kind=4) :: s_x_c2, s_v_c2
  s_x_c2 = 10
  s_v_c2 = 10

!$omp atomic read seq_cst
  s_v_c2 = s_x_c2
!$omp end atomic
  write(6,*) "s_v_c2 = ", s_v_c2, " s_x_c2 = ", s_x_c2
end subroutine sub2

program main
  call sub2()
end program main
```

```
$ flang-new -fopenmp OMP_3_O_007_4_atm_type_140_re_.f90
flang-new: /lustre/home/ohno/LLVM_20240523/llvm-project/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:5894: llvm::OpenMPIRBuilder::InsertPointTy llvm::OpenMPIRBuilder::createAtomicRead(const llvm::OpenMPIRBuilder::LocationDescription&, llvm::OpenMPIRBuilder::AtomicOpValue&, llvm::OpenMPIRBuilder::AtomicOpValue&, llvm::AtomicOrdering): Assertion `(XElemTy->isFloatingPointTy() || XElemTy->isIntegerTy() || XElemTy->isPointerTy()) && "OMP atomic read expected a scalar type"' failed.
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_20240523/release/bin/flang-new -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -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 -fopenmp -resource-dir /lustre/home/ohno/LLVM_20240523/release/bin/.. -mframe-pointer=non-leaf -o /tmp/OMP_3_O_007_4_atm_type_140_re_-f6c793.o -x f95-cpp-input OMP_3_O_007_4_atm_type_140_re_.f90
 #0 0x0000000004251280 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lustre/home/ohno/LLVM_20240523/release/bin/flang-new+0x4251280)
 #1 0x000000000424f188 llvm::sys::RunSignalHandlers() (/lustre/home/ohno/LLVM_20240523/release/bin/flang-new+0x424f188)
 #2 0x000000000424f30c SignalHandler(int) Signals.cpp:0:0
 #3 0x00004000044607a0 (linux-vdso.so.1+0x7a0)
 #4 0x0000400004906274 raise (/lib64/libc.so.6+0x36274)
 #5 0x00004000048f0a2c abort (/lib64/libc.so.6+0x20a2c)
 #6 0x00004000048ffba0 __assert_fail_base (/lib64/libc.so.6+0x2fba0)
 #7 0x00004000048ffc18 __assert_perror_fail (/lib64/libc.so.6+0x2fc18)
 #8 0x000000000728bf20 llvm::OpenMPIRBuilder::emitTaskwaitImpl(llvm::OpenMPIRBuilder::LocationDescription const&) (/lustre/home/ohno/LLVM_20240523/release/bin/flang-new+0x728bf20)
 #9 0x00000000059d86cc convertHostOrTargetOperation(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) OpenMPToLLVMIRTranslation.cpp:0:0
#10 0x00000000059d9a5c (anonymous namespace)::OpenMPDialectLLVMIRTranslationInterface::convertOperation(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) const OpenMPToLLVMIRTranslation.cpp:0:0
#11 0x0000000006047370 mlir::LLVM::ModuleTranslation::convertOperation(mlir::Operation&, llvm::IRBuilderBase&, bool) (/lustre/home/ohno/LLVM_20240523/release/bin/flang-new+0x6047370)
#12 0x00000000060509ec mlir::LLVM::ModuleTranslation::convertBlockImpl(mlir::Block&, bool, llvm::IRBuilderBase&, bool) (/lustre/home/ohno/LLVM_20240523/release/bin/flang-new+0x60509ec)
#13 0x00000000060516a0 mlir::LLVM::ModuleTranslation::convertOneFunction(mlir::LLVM::LLVMFuncOp) (/lustre/home/ohno/LLVM_20240523/release/bin/flang-new+0x60516a0)
#14 0x000000000605200c mlir::LLVM::ModuleTranslation::convertFunctions() (/lustre/home/ohno/LLVM_20240523/release/bin/flang-new+0x605200c)
#15 0x00000000060569d8 mlir::translateModuleToLLVMIR(mlir::Operation*, llvm::LLVMContext&, llvm::StringRef) (/lustre/home/ohno/LLVM_20240523/release/bin/flang-new+0x60569d8)
#16 0x00000000048c3098 Fortran::frontend::CodeGenAction::generateLLVMIR() (/lustre/home/ohno/LLVM_20240523/release/bin/flang-new+0x48c3098)
#17 0x00000000048c53c4 Fortran::frontend::CodeGenAction::executeAction() (/lustre/home/ohno/LLVM_20240523/release/bin/flang-new+0x48c53c4)
#18 0x0000000004285cdc Fortran::frontend::FrontendAction::execute() (/lustre/home/ohno/LLVM_20240523/release/bin/flang-new+0x4285cdc)
#19 0x000000000427ab04 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/lustre/home/ohno/LLVM_20240523/release/bin/flang-new+0x427ab04)
#20 0x000000000428b298 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/lustre/home/ohno/LLVM_20240523/release/bin/flang-new+0x428b298)
#21 0x0000000003e886d0 fc1_main(llvm::ArrayRef<char const*>, char const*) (/lustre/home/ohno/LLVM_20240523/release/bin/flang-new+0x3e886d0)
#22 0x0000000003dfc138 main (/lustre/home/ohno/LLVM_20240523/release/bin/flang-new+0x3dfc138)
#23 0x00004000048f4384 __libc_start_main (/lib64/libc.so.6+0x24384)
#24 0x0000000003e87554 _start (/lustre/home/ohno/LLVM_20240523/release/bin/flang-new+0x3e87554)
flang-new: error: unable to execute command: Aborted (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 8930ba98e01bc66949e482b396f8389d64388359)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /lustre/home/ohno/LLVM_20240523/release/bin
Build config: +assertions
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_3_O_007_4_atm_type_140_re_-65119c
flang-new: note: diagnostic msg: /tmp/OMP_3_O_007_4_atm_type_140_re_-65119c.sh
flang-new: note: diagnostic msg:

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

```
$ cat /tmp/OMP_3_O_007_4_atm_type_140_re_-65119c
#line "./OMP_3_O_007_4_atm_type_140_re_.f90" 1
      subroutine sub2()
 complex(kind=4) :: s_x_c2, s_v_c2
      s_x_c2 = 10
      s_v_c2 = 10

!$omp atomic read seq_cst
      s_v_c2 = s_x_c2
!$omp end atomic
      write(6,*) "s_v_c2 = ", s_v_c2, " s_x_c2 = ", s_x_c2
 end subroutine sub2

      program main
      call sub2()
 end program main
$
```

```
$ cat /tmp/OMP_3_O_007_4_atm_type_140_re_-65119c.sh
# Crash reproducer for clang version 19.0.0git (https://github.com/llvm/llvm-project.git 8930ba98e01bc66949e482b396f8389d64388359)
# Driver args: "-fopenmp" "OMP_3_O_007_4_atm_type_140_re_.f90"
# Original command: "/lustre/home/ohno/LLVM_20240523/release/bin/flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu" "-emit-obj" "-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" "-fopenmp" "-resource-dir" "/lustre/home/ohno/LLVM_20240523/release/bin/.." "-mframe-pointer=non-leaf" "-o" "/tmp/OMP_3_O_007_4_atm_type_140_re_-f6c793.o" "-x" "f95-cpp-input" "OMP_3_O_007_4_atm_type_140_re_.f90"
 "/lustre/home/ohno/LLVM_20240523/release/bin/flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu" "-emit-obj" "-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" "-fopenmp" "-mframe-pointer=non-leaf" "-x" "f95-cpp-input" "OMP_3_O_007_4_atm_type_140_re_-65119c"
$
```


```
$ gfortran -fopenmp OMP_3_O_007_4_atm_type_140_re_.f90; ./a.out
 s_v_c2 = (10.0000000,0.00000000)  s_x_c2 = (10.0000000,0.00000000)
$
```

```
$ ifort -qopenmp -diag-disable=10448 OMP_3_O_007_4_atm_type_140_re_.f90; ./a.out
 s_v_c2 = (10.00000,0.0000000E+00)  s_x_c2 = (10.00000,0.0000000E+00)
$
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWltv2zoS_jXMCyFDoi6WHvLgXNwGaDdBmz27bwZFjRyeSqQOSTnJv1-Quthy3DhJ3T1YYI02lqnh8JvhXEgOqdZ8LQDOUXyB4qsz2poHqc7lg5Be-edZLovnc5T4_T__CvmLP0BpLgWWJS4rKtaegEeMwgUOspk_8xFJy4IVLCzmcUZIVPrAfBpCNCflPIv8Isr9MqRBPs8QyRBZLhaKPSRRx3xvrO7vjcAWHgmzMIoCFF8hkj4Y02gULhBZIrJcc_PQ5jMma0SWVbUZvrxGyT-BGUSWXOsWNCLLjokd-hI_PoDAFBe8LEGBMBglvnluACU-5hq3GgrMhW1ltDGtAk8baqAGYRyJe0WNrDnDCmhhG5kU2qjWDnqJzQNgJuuGV9RYpRlQNRfUgMY0F1LVtKqeZxh3gn6Wj7ABNSKzvTWt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