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

    <tr>
        <th>Summary</th>
        <td>
            [mlir] --finalize-memref-to-llvm crashed with assertion failure 'this->_M_is_engaged()'
        </td>
    </tr>

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

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

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

<pre>
    git version: fe5370dd50e48f827aaee9f5fa80e751b1759a25

system: `Ubuntu 20.04.6 LTS (Focal Fossa)`

reproduced with:
`mlir-opt --finalize-memref-to-llvm reduced.mlir`

reduced.mlir:
```
%c15 = arith.constant 15 : index
%alloc = memref.alloc(%c15) : memref<?x10xf32, #spirv.storage_class<StorageBuffer>>
```

trance:
```
/usr/include/c++/9/optional:438: constexpr _Tp& std::_Optional_base_impl<_Tp, _Dp>::_M_get() [with _Tp = unsigned int; _Dp = std::_Optional_base<unsigned int, true, true>]: Assertion 'this->_M_is_engaged()' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt --finalize-memref-to-llvm reduced.mlir
 #0 0x00005582077366ff llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x14096ff)
 #1 0x0000558207733984 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f69200c5420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f691fb6200b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007f691fb41859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x0000558207712868 (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x13e5868)
 #6 0x000055820979bee1 castAllocFuncResult(mlir::ConversionPatternRewriter&, mlir::Location, mlir::Value, mlir::MemRefType, mlir::Type, mlir::LLVMTypeConverter&) AllocLikeConversion.cpp:0:0
 #7 0x000055820979c882 mlir::AllocationOpLLVMLowering::allocateBufferManuallyAlign(mlir::ConversionPatternRewriter&, mlir::Location, mlir::Value, mlir::Operation*, mlir::Value) const (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x346f882)
 #8 0x000055820978f8d8 (anonymous namespace)::AllocOpLowering::allocateBuffer(mlir::ConversionPatternRewriter&, mlir::Location, mlir::Value, mlir::Operation*) const MemRefToLLVM.cpp:0:0
 #9 0x000055820979d8b9 mlir::AllocLikeOpLLVMLowering::matchAndRewrite(mlir::Operation*, llvm::ArrayRef<mlir::Value>, mlir::ConversionPatternRewriter&) const (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x34708b9)
#10 0x0000558209fe1a7a mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x3cb4a7a)
#11 0x000055820cba91e8 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>) (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x687c1e8)
#12 0x0000558209ff0e19 (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) DialectConversion.cpp:0:0
#13 0x0000558209ff17a7 (anonymous namespace)::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>, llvm::function_ref<void (mlir::Diagnostic&)>) DialectConversion.cpp:0:0
#14 0x0000558209ff3c14 mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget&, mlir::FrozenRewritePatternSet const&, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>*) (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x3cc6c14)
#15 0x0000558209790642 (anonymous namespace)::FinalizeMemRefToLLVMConversionPass::runOnOperation() MemRefToLLVM.cpp:0:0
#16 0x0000558209f6113e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x3c3413e)
#17 0x0000558209f6161a mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x3c3461a)
#18 0x0000558209f61e21 mlir::PassManager::run(mlir::Operation*) (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x3c34e21)
#19 0x0000558209f522cb performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#20 0x0000558209f53784 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPool*) MlirOptMain.cpp:0:0
#21 0x0000558209f53934 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#22 0x000055820a039ff4 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, s
td::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x3d0cff4)
#23 0x0000558209f4cd57 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x3c1fd57)
#24 0x0000558209f53c5b mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x3c26c5b)
#25 0x00005582076717db main (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x13447db)
#26 0x00007f691fb43083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#27 0x000055820770829e _start (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x13db29e)
Aborted (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWttu4zjSfhrmhohBUeeLXLidGP8AMRJ08s-tQVElmds0qSWp7niefiFKsSXl2LPTnsE23FbEQ6m-r6pYRdHMWlErgCsUf0Hx9QVr3U6bK6a0Oux1azerh4tCl4erWjj8HYwVWqFw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