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

    <tr>
        <th>Summary</th>
        <td>
            [flang] [OpenMP] crash with Assertion `AggOutputArgBegin != newFunction->arg_end() && "Number of aggregate output arguments should match " "the number of defined values"' failed.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            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 the subroutine `dep3` in https://github.com/gcc-mirror/gcc/blob/master/libgomp/testsuite/libgomp.fortran/depend-1.f90.

```console
$ cat test.f90
subroutine test
    integer :: x

    !$omp parallel private(x)

        !$omp task shared (x) depend(in: x)
 !$omp endtask

    !$omp end parallel
end subroutine test
```

Assertion:
```console
flang-new: /tmp/llvm-project/llvm/lib/Transforms/Utils/CodeExtractor.cpp:1363: llvm::CallInst *llvm::CodeExtractor::emitCallAndSwitchStatement(llvm::Function *, llvm::BasicBlock *, llvm::CodeExtractor::ValueSet &, llvm::CodeExtractor::ValueSet &): Assertion `AggOutputArgBegin != newFunction->arg_end() && "Number of aggregate output arguments should match " "the number of defined values"' failed.
```

Stack dump:
```console
 #0 0x00005646dffb9359 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
 #1 0x00005646dffb99d4 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f19267de520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007f1926832a7c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #4 0x00007f1926832a7c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #5 0x00007f1926832a7c pthread_kill ./nptl/pthread_kill.c:89:10
 #6 0x00007f19267de476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #7 0x00007f19267c47f3 abort ./stdlib/abort.c:81:7
 #8 0x00007f19267c471b _nl_load_domain ./intl/loadmsgcat.c:1177:9
 #9 0x00007f19267d5e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#10 0x00005646e247539e std::map<llvm::BasicBlock*, llvm::BasicBlock*, std::less<llvm::BasicBlock*>, std::allocator<std::pair<llvm::BasicBlock* const, llvm::BasicBlock*>>>::operator[](llvm::BasicBlock* const&) 
#11 0x00005646e24763d7 llvm::CodeExtractor::extractCodeRegion(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>&) 
#12 0x00005646e24758a8 llvm::CodeExtractor::extractCodeRegion(llvm::CodeExtractorAnalysisCache const&) 
#13 0x00005646e21a5d82 llvm::OpenMPIRBuilder::finalize(llvm::Function*) 
#14 0x00005646e1574281 mlir::LLVM::ModuleTranslation::~ModuleTranslation() 
#15 0x00005646e1578ef4 mlir::translateModuleToLLVMIR(mlir::Operation*, llvm::LLVMContext&, llvm::StringRef) 
#16 0x00005646e03ce624 Fortran::frontend::CodeGenAction::generateLLVMIR() 
#17 0x00005646e03d01ee Fortran::frontend::CodeGenAction::executeAction() 
#18 0x00005646dffd9d2c Fortran::frontend::FrontendAction::execute() 
#19 0x00005646dffd0bc3 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) 
#20 0x00005646dffdcb7e Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) 
#21 0x00005646dfca113d fc1_main(llvm::ArrayRef<char const*>, char const*) 
#22 0x00005646dfca0126 main 
#23 0x00007f19267c5d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#24 0x00007f19267c5e40 call_init ./csu/../csu/libc-start.c:128:20
#25 0x00007f19267c5e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#26 0x00005646dfc9f685 _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/eJzcWF1z2ywW_jXkholHAn1e5EJJ6n0783b7TtPtrQfDkcwGgQZQku7F_vYdkGzLjuu2F3uxOxO30oHzPOcLOIg5JzsNcIfye5Q_3rDR74y9e75l1ppXd7M14vvdH2ABS4f9DrCFwRoxcrCIPODXneS7MGQhyARmWuDeCNlKELi1po9KbtxaM3qpAaMiETBQVCRYarzzfnCINoisEVl30u_G7YqbPrxwfttLa42dXhBZb5XZIrLumfOBfq3ktjP9gMjag_NulB6O0lVrrLdMI7IWMIAWt-mqrZMVSh5R0sz_Fsn0x412RsEsJRnmzOMAGlQm6cKHMDAJMcZYag8dWBzcoA1-WxKEcURSRDLTD3hglikFCg9WvrBgbPWGSH2ucKrkmXvGbscsCDwr4MkhRCqpJ8o9yEIPtAiqP7YGtDhYNI0HyUU3D3FaojXOgfXSBBOuhbNVTHe3Gl6DqSFXMWNKvfS3gzX_BO7n1yl3iKy_WqZda2zvEFn_w0sV_n8wAj68ecu4N3bFhwHRJqUFDahRO4b_gSn1UTuPEWkW0qXuJIJe-jC50eLpVXq-e_LMQw_aI1IdNdej5sHHgBcK_jhyz5zk98rw5_djF_i-MTXCEwTDit-cXAcXD9EOK6jpus-jH0bf2O4eOqljWukj1vC6t_gW0Q_MdpupUELVRLACI0L-PvZbsNi0mHWdhY55wCYCYma7MUTBYbczoxK4Z57vglL4hcWsD8oCWqlB4JdgrkOEIFLilkkFYnWlcJ48489YjP3wk8rBiNAEJ29JkiR5kRWibbc1zetF8Nx3Nz38ZaX2EfmrZRxOkmjZ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