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

    <tr>
        <th>Summary</th>
        <td>
            [flang] [OpenMP] [mlir] crash with "Unhandled reduction container" and "UNREACHABLE executed"
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir,
            flang
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          k-arrows
      </td>
    </tr>
</table>

<pre>
    Here is the reproducer, which is reduced and modified from https://github.com/gcc-mirror/gcc/blob/master/libgomp/testsuite/libgomp.fortran/lib1.f90.

```console
$ cat test.f90
  use omp_lib

  logical :: l

!$omp parallel reduction (.or.:l)
!$omp master
  l = l .or. l
!$omp end master
!$omp end parallel

end
```

Printed message before crash:
```console
Unhandled reduction container
UNREACHABLE executed at /tmp/llvm-project/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1468!
```

Stack dump:
```console
 #0 0x0000557a3c48a359 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
 #1 0x0000557a3c48a9d4 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f8186b3b520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007f8186b8fa7c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #4 0x00007f8186b8fa7c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #5 0x00007f8186b8fa7c pthread_kill ./nptl/pthread_kill.c:89:10
 #6 0x00007f8186b3b476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #7 0x00007f8186b217f3 abort ./stdlib/abort.c:81:7
 #8 0x0000557a3c44eb52 llvm::install_out_of_memory_new_handler() 
 #9 0x0000557a3d5902d0 (anonymous namespace)::OpenMPDialectLLVMIRTranslationInterface::convertOperation(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) const OpenMPToLLVMIRTranslation.cpp:0:0
#10 0x0000557a3da45f90 mlir::LLVM::ModuleTranslation::convertOperation(mlir::Operation&, llvm::IRBuilderBase&) 
#11 0x0000557a3da46280 mlir::LLVM::ModuleTranslation::convertBlock(mlir::Block&, bool, llvm::IRBuilderBase&) 
#12 0x0000557a3d59517b convertOmpOpRegions(mlir::Region&, llvm::StringRef, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&, mlir::LogicalResult&, llvm::SmallVectorImpl<llvm::PHINode*>*) OpenMPToLLVMIRTranslation.cpp:0:0
#13 0x0000557a3d596c7c void llvm::function_ref<void (llvm::IRBuilderBase::InsertPoint, llvm::IRBuilderBase::InsertPoint)>::callback_fn<convertOmpMaster(mlir::Operation&, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&)::$_22>(long, llvm::IRBuilderBase::InsertPoint, llvm::IRBuilderBase::InsertPoint) OpenMPToLLVMIRTranslation.cpp:0:0
#14 0x0000557a3e67c99d llvm::OpenMPIRBuilder::EmitOMPInlinedRegion(llvm::omp::Directive, llvm::Instruction*, llvm::Instruction*, llvm::function_ref<void (llvm::IRBuilderBase::InsertPoint, llvm::IRBuilderBase::InsertPoint)>, std::function<void (llvm::IRBuilderBase::InsertPoint)>, bool, bool, bool) 
#15 0x0000557a3e67ddd3 llvm::OpenMPIRBuilder::createMaster(llvm::OpenMPIRBuilder::LocationDescription const&, llvm::function_ref<void (llvm::IRBuilderBase::InsertPoint, llvm::IRBuilderBase::InsertPoint)>, std::function<void (llvm::IRBuilderBase::InsertPoint)>)
#16 0x0000557a3d58e0cf (anonymous namespace)::OpenMPDialectLLVMIRTranslationInterface::convertOperation(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) const OpenMPToLLVMIRTranslation.cpp:0:0
#17 0x0000557a3da45f90 mlir::LLVM::ModuleTranslation::convertOperation(mlir::Operation&, llvm::IRBuilderBase&) 
#18 0x0000557a3da46280 mlir::LLVM::ModuleTranslation::convertBlock(mlir::Block&, bool, llvm::IRBuilderBase&) 
#19 0x0000557a3d59517b convertOmpOpRegions(mlir::Region&, llvm::StringRef, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&, mlir::LogicalResult&, llvm::SmallVectorImpl<llvm::PHINode*>*) OpenMPToLLVMIRTranslation.cpp:0:0
#20 0x0000557a3d594438 void llvm::function_ref<void (llvm::IRBuilderBase::InsertPoint, llvm::IRBuilderBase::InsertPoint)>::callback_fn<convertOmpParallel(mlir::omp::ParallelOp, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&)::$_31>(long, llvm::IRBuilderBase::InsertPoint, llvm::IRBuilderBase::InsertPoint) OpenMPToLLVMIRTranslation.cpp:0:0
#21 0x0000557a3e679b76 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) 
#22 0x0000557a3d58df74 (anonymous namespace)::OpenMPDialectLLVMIRTranslationInterface::convertOperation(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) const OpenMPToLLVMIRTranslation.cpp:0:0
#23 0x0000557a3da45f90 mlir::LLVM::ModuleTranslation::convertOperation(mlir::Operation&, llvm::IRBuilderBase&) 
#24 0x0000557a3da46280 mlir::LLVM::ModuleTranslation::convertBlock(mlir::Block&, bool, llvm::IRBuilderBase&) 
#25 0x0000557a3da47670 mlir::LLVM::ModuleTranslation::convertOneFunction(mlir::LLVM::LLVMFuncOp) 
#26 0x0000557a3da48974 mlir::LLVM::ModuleTranslation::convertFunctions() 
#27 0x0000557a3da49dae mlir::translateModuleToLLVMIR(mlir::Operation*, llvm::LLVMContext&, llvm::StringRef) 
#28 0x0000557a3c89f624 Fortran::frontend::CodeGenAction::generateLLVMIR() 
#29 0x0000557a3c8a11ee Fortran::frontend::CodeGenAction::executeAction() 
#30 0x0000557a3c4aad2c Fortran::frontend::FrontendAction::execute() 
#31 0x0000557a3c4a1bc3 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) 
#32 0x0000557a3c4adb7e Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) 
#33 0x0000557a3c17213d fc1_main(llvm::ArrayRef<char const*>, char const*) 
#34 0x0000557a3c171126 main 
#35 0x00007f8186b22d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#36 0x00007f8186b22e40 call_init ./csu/../csu/libc-start.c:128:20
#37 0x00007f8186b22e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#38 0x0000557a3c170685 _start
flang-new: error: unable to execute command: Aborted
flang-new: error: flang frontend command failed due to signal (use -v to see invocation)
flang-new version 18.0.0 (https://github.com/llvm/llvm-project.git a8e0acf660639078a7e5341dd6ec82326d3b796b)
Target: x86_64-unknown-linux-gnu
Thread model: posix
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWktv3DgS_jX0hXBDot4HH9p2ehNsMgk8mbk2KLHUzTVFCiTlx79fkJK6Jdlp28Fk14tZIA-pVPzqSVaZZWoM30mAC5RcouT6jHZ2r_TF7TnVWt2bs1Kxx4uPoAFzg-0esIZWK9ZVoBG5wvd7Xu3dJw2OxjCVDDeK8ZoDw7VWDd5b2xoUrRHZILLZcbvvylWlGvdSVecN11rp_gWRTSlUicimocY6CRvBy51qWkQ2Fow1HbdwpK5qpa2msqeEq7oIVii4RsF6-DcN-j-VkkYJGKgkxhW12AG6JT0V484AVk27FbycgmAs1I5XVGBnRLTGYiaChIjEqmlxSzUVAkTvCsuVxIjkK6V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