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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR] `mlir::Operation::getRegions()`crashed with segmentation fault
        </td>
    </tr>

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

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

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

<pre>
    Test on [llvm16](https://github.com/llvm/llvm-project/tree/release/16.x)
Steps to reproduceļ¼š
```
mlir-opt test.mlir -affine-data-copy-generate="generate-dma=false fast-mem-space=0 fast-mem-capacity=1"
```
test case:
```
module {
  func.func @main()  {
    %true = spirv.Constant true
    %alloc = memref.alloc() {alignment = 64 : i64} : memref<i1>
    affine.store %true, %alloc[] : memref<i1>
    return
  }
}
```
crash trace:
```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: mlir-opt test.mlir "-affine-data-copy-generate=generate-dma=false fast-mem-space=0 fast-mem-capacity=1"
 #0 0x0000000000481cad llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/ty/llvm16/llvm/lib/Support/Unix/Signals.inc:567:11
 #1 0x000000000048213b PrintStackTraceSignalHandler(void*) /home/ty/llvm16/llvm/lib/Support/Unix/Signals.inc:641:1
 #2 0x00000000004804d6 llvm::sys::RunSignalHandlers() /home/ty/llvm16/llvm/lib/Support/Signals.cpp:104:5
 #3 0x0000000000482865 SignalHandler(int) /home/ty/llvm16/llvm/lib/Support/Unix/Signals.inc:412:1
 #4 0x00007ff0c42c8980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #5 0x00000000004118a4 mlir::Operation::getRegions() /home/ty/llvm16/mlir/include/mlir/IR/Operation.h:524:9
 #6 0x0000000003d9794a mlir::detail::walk(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) /home/ty/llvm16/mlir/lib/IR/Visitors.cpp:61:27
 #7 0x0000000000632b22 std::enable_if<llvm::is_one_of<mlir::Operation*, mlir::Operation*, mlir::Region*, mlir::Block*>::value, void>::type mlir::detail::walk<(mlir::WalkOrder)1, (anonymous namespace)::AffineDataCopyGeneration::runOnOperation()::$_2, mlir::Operation*, void>(mlir::Operation*, (anonymous namespace)::AffineDataCopyGeneration::runOnOperation()::$_2&&) /home/ty/llvm16/mlir/include/mlir/IR/Visitors.h:171:3
 #8 0x000000000063256d std::enable_if<llvm::function_traits<std::decay<(anonymous namespace)::AffineDataCopyGeneration::runOnOperation()::$_2>::type>::num_args == 1, void>::type mlir::Operation::walk<(mlir::WalkOrder)1, (anonymous namespace)::AffineDataCopyGeneration::runOnOperation()::$_2, void>((anonymous namespace)::AffineDataCopyGeneration::runOnOperation()::$_2&&) /home/ty/llvm16/mlir/include/mlir/IR/Operation.h:621:5
 #9 0x0000000000631bd4 (anonymous namespace)::AffineDataCopyGeneration::runOnOperation() /home/ty/llvm16/mlir/lib/Dialect/Affine/Transforms/AffineDataCopyGeneration.cpp:225:24
#10 0x0000000003a696b7 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/ty/llvm16/mlir/lib/Pass/Pass.cpp:471:21
#11 0x0000000003a69ccd mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/ty/llvm16/mlir/lib/Pass/Pass.cpp:534:16
#12 0x0000000003a6f138 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_14::operator()(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&) const /home/ty/llvm16/mlir/lib/Pass/Pass.cpp:754:36
#13 0x0000000003a6eda9 mlir::LogicalResult mlir::failableParallelForEach<__gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_14&>(mlir::MLIRContext*, __gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>, __gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_14&) /home/ty/llvm16/mlir/include/mlir/IR/Threading.h:46:18
#14 0x0000000003a6af73 mlir::LogicalResult mlir::failableParallelForEach<std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>&, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_14&>(mlir::MLIRContext*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>&, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_14&) /home/ty/llvm16/mlir/include/mlir/IR/Threading.h:92:10
#15 0x0000000003a6a817 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) /home/ty/llvm16/mlir/lib/Pass/Pass.cpp:764:14
#16 0x0000000003a69987 mlir::detail::OpToOpPassAdaptor::runOnOperation(bool) /home/ty/llvm16/mlir/lib/Pass/Pass.cpp:655:5
#17 0x0000000003a696a8 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/ty/llvm16/mlir/lib/Pass/Pass.cpp:468:5
#18 0x0000000003a69ccd mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/ty/llvm16/mlir/lib/Pass/Pass.cpp:534:16
#19 0x0000000003a6b60c mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /home/ty/llvm16/mlir/lib/Pass/Pass.cpp:839:10
#20 0x0000000003a6b531 mlir::PassManager::run(mlir::Operation*) /home/ty/llvm16/mlir/lib/Pass/Pass.cpp:819:60
#21 0x0000000003a61e92 performActions(llvm::raw_ostream&, bool, bool, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, bool, bool) /home/ty/llvm16/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:91:17
#22 0x0000000003a61aef processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, bool, bool, bool, bool, bool, bool, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, llvm::ThreadPool*) /home/ty/llvm16/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:139:12
#23 0x0000000003a618a8 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool)::$_0::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/ty/llvm16/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:181:12
#24 0x0000000003a6179d 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>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) /home/ty/llvm16/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12
#25 0x0000000003b939f9 llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/ty/llvm16/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:12
#26 0x0000000003b92fd5 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) /home/ty/llvm16/mlir/lib/Support/ToolUtilities.cpp:28:12
#27 0x0000000003a607d3 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool) /home/ty/llvm16/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:186:10
#28 0x0000000003a6096f mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool, bool) /home/ty/llvm16/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:209:10
#29 0x0000000003a615b1 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) /home/ty/llvm16/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:306:14
#30 0x0000000000411609 main /home/ty/llvm16/mlir/tools/mlir-opt/mlir-opt.cpp:271:7
#31 0x00007ff0c319bc87 __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:344:0
#32 0x00000000004112ea _start (/home/ty/llvm16/llvm/mlir/build/bin/mlir-opt+0x4112ea)
Segmentation fault (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsW99zozjy_2uUF5VdSMIYHvLg2PH3O1eTSiqT3avaF5cAYetGSJwkZuL__krCBowncZL17OT2kkoZEELq_vQPdTeCGsPXkrFLMLkCk8UFre1G6csrRsUfrNps9UWq8u3lAzMWKgnB5EqIbyWKwGQBcLyxtjKAzABeArxcc7up03GmSoCXrtvuMKq0-hfLLMBLqxkDeKmZYNS4MxSNHwFOQLAAweyLZZWBVkHNKq3yOmPgegmu5iCZNR1AFOz-_WUpuB6pykLLjB27KziiRcElG-XU0lGmqu1ozSTT1DJAFgDj_dUoLykgi4IKw2BBjR2VrByZimauY9A1ZbSiGbdbQBYIYPxDOtz0MHMMkScIVXktGATTq-YawqKW2dj9QBAGJeUS4BjgBPb7QAjwxOqaQUAW0FRcfxvPlTSWSgtd-0FHKoTKfM-SlZoVY9-wG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