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

    <tr>
        <th>Summary</th>
        <td>
            [Flang][OpenMP] Flang crash in lowering OpenMP parallel do with nested tile transformation
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          chandraghale
      </td>
    </tr>
</table>

<pre>
    Flang crashes during lowering for a valid OpenMP loop-transformation pattern where !$omp tile is nested under !$omp parallel do.
[https://godbolt.org/z/b7zecYEMT](https://godbolt.org/z/b7zecYEMT)
Reproducer 
```
subroutine func7(A)
  implicit none
  double precision :: A(100,100)
  integer :: i, j
  !$omp parallel do
  !$omp tile sizes(4,16)
  do i = 1, 100
    do j = 1, 100
      A(j,i) = A(j,i) + 1
 end do
  end do
end subroutine
```

```
> ./flang -fopenmp -fopenmp-version=51 tile02.f90 
warning: OpenMP support for version 51 in flang is still incomplete
flang: /ptmp/ghc/llvm-project/flang/lib/Lower/OpenMP/Utils.cpp:706: pft::Evaluation *Fortran::lower::omp::getNestedDoConstruct(pft::Evaluation &): Assertion `nested.getIf<parser::DoConstruct>() && "Unexpected construct in the nested evaluations"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.      Program arguments: /ptmp/ghc/llvm-project/install/bin/flang -fc1 -triple x86_64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -fopenmp -fopenmp-version=51 -resource-dir /ptmp/ghc/llvm-project/install/lib/clang/23 -mframe-pointer=all -o /tmp/tile02-f06263.o -x f95 tile02.f90
 #0 0x00007f3e53bc14dd llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /ptmp/ghc/llvm-project/llvm/lib/Support/Unix/Signals.inc:880:11
 #1 0x00007f3e53bc1a0b PrintStackTraceSignalHandler(void*) /ptmp/ghc/llvm-project/llvm/lib/Support/Unix/Signals.inc:962:1
 #2 0x00007f3e53bbf868 llvm::sys::RunSignalHandlers() /ptmp/ghc/llvm-project/llvm/lib/Support/Signals.cpp:108:5
 #3 0x00007f3e53bc2129 SignalHandler(int, siginfo_t*, void*) /ptmp/ghc/llvm-project/llvm/lib/Support/Unix/Signals.inc:448:38
 #4 0x00007f3e4c657900 __restore_rt (/lib64/libc.so.6+0x57900)
 #5 0x00007f3e4c6a8dfc __pthread_kill_implementation (/lib64/libc.so.6+0xa8dfc)
 #6 0x00007f3e4c657842 gsignal (/lib64/libc.so.6+0x57842)
 #7 0x00007f3e4c63f5cf abort (/lib64/libc.so.6+0x3f5cf)
 #8 0x00007f3e4c63f4e7 _nl_load_domain.cold (/lib64/libc.so.6+0x3f4e7)
 #9 0x00007f3e4c64fb32 (/lib64/libc.so.6+0x4fb32)
#10 0x000000000baaa38d Fortran::lower::omp::getNestedDoConstruct(Fortran::lower::pft::Evaluation&) /ptmp/ghc/llvm-project/flang/lib/Lower/OpenMP/Utils.cpp:707:13
#11 0x000000000b999198 Fortran::lower::omp::ClauseProcessor::processCollapse(mlir::Location, Fortran::lower::pft::Evaluation&, mlir::omp::LoopRelatedClauseOps&, mlir::omp::CollapseClauseOps&, llvm::SmallVectorImpl<Fortran::semantics::Symbol const*>&) const /ptmp/ghc/llvm-project/flang/lib/Lower/OpenMP/ClauseProcessor.cpp:401:48
#12 0x000000000b66173b genLoopNestClauses(Fortran::lower::AbstractConverter&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, llvm::SmallVector<Fortran::lower::omp::Clause, 0u> const&, mlir::Location, mlir::omp::detail::Clauses<mlir::omp::CollapseClauseOps, mlir::omp::LoopRelatedClauseOps, mlir::omp::TileSizesClauseOps>&, llvm::SmallVectorImpl<Fortran::semantics::Symbol const*>&) /ptmp/ghc/llvm-project/flang/lib/Lower/OpenMP/OpenMP.cpp:1593:29
#13 0x000000000b65a6c5 genStandaloneDo(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::lower::StatementContext&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, mlir::Location, llvm::SmallVector<tomp::DirectiveWithClauses<Fortran::lower::omp::Clause>, 0u> const&, tomp::DirectiveWithClauses<Fortran::lower::omp::Clause> const*) /ptmp/ghc/llvm-project/flang/lib/Lower/OpenMP/OpenMP.cpp:3239:18
#14 0x000000000b6594f6 genOMPDispatch(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, mlir::Location, llvm::SmallVector<tomp::DirectiveWithClauses<Fortran::lower::omp::Clause>, 0u> const&, tomp::DirectiveWithClauses<Fortran::lower::omp::Clause> const*) /ptmp/ghc/llvm-project/flang/lib/Lower/OpenMP/OpenMP.cpp:3755:13
#15 0x000000000b661f1b createBodyOfOp(mlir::Operation&, OpWithBodyGenInfo const&, llvm::SmallVector<tomp::DirectiveWithClauses<Fortran::lower::omp::Clause>, 0u> const&, tomp::DirectiveWithClauses<Fortran::lower::omp::Clause> const*) /ptmp/ghc/llvm-project/flang/lib/Lower/OpenMP/OpenMP.cpp:1255:5
#16 0x000000000b661ba9 mlir::omp::ParallelOp genOpWithBody<mlir::omp::ParallelOp, mlir::omp::detail::Clauses<mlir::omp::AllocateClauseOps, mlir::omp::IfClauseOps, mlir::omp::NumThreadsClauseOps, mlir::omp::PrivateClauseOps, mlir::omp::ProcBindClauseOps, mlir::omp::ReductionClauseOps>&>(OpWithBodyGenInfo const&, llvm::SmallVector<tomp::DirectiveWithClauses<Fortran::lower::omp::Clause>, 0u> const&, tomp::DirectiveWithClauses<Fortran::lower::omp::Clause> const*, mlir::omp::detail::Clauses<mlir::omp::AllocateClauseOps, mlir::omp::IfClauseOps, mlir::omp::NumThreadsClauseOps, mlir::omp::PrivateClauseOps, mlir::omp::ProcBindClauseOps, mlir::omp::ReductionClauseOps>&) /ptmp/ghc/llvm-project/flang/lib/Lower/OpenMP/OpenMP.cpp:1488:3
#17 0x000000000b66150e genParallelOp(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, mlir::Location, llvm::SmallVector<tomp::DirectiveWithClauses<Fortran::lower::omp::Clause>, 0u> const&, tomp::DirectiveWithClauses<Fortran::lower::omp::Clause> const*, mlir::omp::detail::Clauses<mlir::omp::AllocateClauseOps, mlir::omp::IfClauseOps, mlir::omp::NumThreadsClauseOps, mlir::omp::PrivateClauseOps, mlir::omp::ProcBindClauseOps, mlir::omp::ReductionClauseOps>&, Fortran::common::openmp::EntryBlockArgs const&, Fortran::lower::omp::DataSharingProcessor*, bool) /ptmp/ghc/llvm-project/flang/lib/Lower/OpenMP/OpenMP.cpp:2522:7
#18 0x000000000b65b302 genStandaloneParallel(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::lower::StatementContext&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, mlir::Location, llvm::SmallVector<tomp::DirectiveWithClauses<Fortran::lower::omp::Clause>, 0u> const&, tomp::DirectiveWithClauses<Fortran::lower::omp::Clause> const*) /ptmp/ghc/llvm-project/flang/lib/Lower/OpenMP/OpenMP.cpp:3278:10
#19 0x000000000b659693 genOMPDispatch(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, mlir::Location, llvm::SmallVector<tomp::DirectiveWithClauses<Fortran::lower::omp::Clause>, 0u> const&, tomp::DirectiveWithClauses<Fortran::lower::omp::Clause> const*) /ptmp/ghc/llvm-project/flang/lib/Lower/OpenMP/OpenMP.cpp:3774:13
#20 0x000000000b671d69 genOMP(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::semantics::SemanticsContext&, Fortran::lower::pft::Evaluation&, Fortran::parser::OpenMPLoopConstruct const&) /ptmp/ghc/llvm-project/flang/lib/Lower/OpenMP/OpenMP.cpp:4550:1
```


</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWltv2zoS_jXMCyFDInV98INjx7sF2pOg6dnFPhkURclsKVIgqVz66xek5NjWOnFOmy727ElRODI1HH4z883wYhJjeCMZm4PkEiBEt0RWmjRbIhhACCSrC9LbrdLzwzcXpaoe52tBZAOpJmbLDKx6zWUDhbpn_qFWGhJ4RwSv4HXH5KcbKJTqAquJNLXSLbFcSdgRa5mW8H7LNIMARQDFqu2g5YJBbqBkxrIK9rJi-uB1RzQRgglYqRkIFyC53FrbGYAXAK0BWjeqKpWwM6UbgNbfAVqX2XdG_3X16QtIVgDlrxdHBQgXn1mnVdVTByJcgDQc_4cL05da9ZZLBute0gygfDH0gZC3neCUWyiVZL6lUn0pGOw0o9w4-x0EvIALgPIoDAFa-s-xu7SscSMOMhygJfzq35x0xOSN96Dh35kBKI-d5nSnuFKQQ4BXMHIq3Yiu1bd_PdUOPb6vAC05QIWXOG5AlzByskxWOyBPj-5h76SJ96Zf8RWcAbSuPbWCWnVMtt3TQ3DHtPMawKsk8gaGaFYXoYvJPdGSy8Y5aqSb6btOaeuZOHaESQS5hIN6bqCxXAjIJVVtJ5h16Pw7pwWgdWfbzrFjSwFaC3HXBp1WXxm1O4iumZcArT862gO0HoYGaP275cLMaNcBvMjC1CnsajtE8uqOiH6gP0CLtdIuJ4ZXPn2GR9V2w0PD7G8-C1ZqqaSxuncA8tPqfIwdoYxhemhLwyGJZg2zH2qAlx3RZjfKoU58BVA-xDMFKIUAod8le-gYdSlId3LOg3bLdqnJnoY3rmKgDNaEC1a5vLz5eLW4vXLhb7mFBJZ9AzXzUbEKTnKQ221fzqhqR2f_p8-5Mb2j8xoSWbmwib5iHouvQrAk9JvVhLLx_YDXIXPD6V0O-x5l3ziEt5bQb7DqB2eHi3AGwuJGq0aTFhLd9C2T1ryCD240IoQrHVweUJhGMLCad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