Skip to content

Title: [mlir] --canonicalize causes the Segmentation Fault in eraseUnreachableBlocks. #77420

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
ghost opened this issue Jan 9, 2024 · 5 comments · Fixed by #83444
Closed
Assignees
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] good first issue https://github.com/llvm/llvm-project/contribute mlir

Comments

@ghost
Copy link

ghost commented Jan 9, 2024

Similar to #74461, but with different content in the unreachable block.

git version: 6e90f13

system: Ubuntu 20.04.6 LTS (Focal Fossa)

reproduced with: mlir-opt --canonicalize a.mlir

a.mlir:

func.func private @func1() {
  %false = arith.constant false
  %c0 = arith.constant 0 : index

  cf.cond_br %false, ^bb1, ^bb2
^bb1:  // pred: ^bb0
  omp.parallel {
    omp.wsloop for  (%arg0) : index = (%c0) to (%c0) step (%c0) {
      %189 = llvm.intr.stacksave : !llvm.ptr
      llvm.br ^bb1
    ^bb1:  // pred: ^bb0
      llvm.br ^bb2
    ^bb2:  // pred: ^bb1
      omp.yield
    }
    omp.terminator
  }
  cf.br ^bb2
^bb2:  // pred: ^bb0
  return
}

trace:

PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /data1/bin-dev/llvm-project/build/bin/mlir-opt --canonicalize a.mlir
 #0 0x000055b186889e4f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x1684e4f)
 #1 0x000055b186886ea4 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007fd721788420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x000055b1896c0d6b mlir::SuccessorRange::SuccessorRange(mlir::Block*) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x44bbd6b)
 #4 0x000055b18942f71f llvm::po_iterator<mlir::Block*, llvm::SmallPtrSet<mlir::Block*, 8u>, false, llvm::GraphTraits<mlir::Block*>>::traverseChild() (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x422a71f)
 #5 0x000055b18942fdeb llvm::iterator_range<llvm::po_iterator<mlir::Block*, llvm::SmallPtrSet<llvm::GraphTraits<mlir::Block*>::NodeRef, 8u>, false, llvm::GraphTraits<mlir::Block*>>> llvm::post_order<mlir::Block*>(mlir::Block* const&) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x422adeb)
 #6 0x000055b1897a8feb mlir::RewriterBase::eraseOp(mlir::Operation*)::'lambda0'(mlir::Operation*)::operator()(mlir::Operation*) const (.isra.0) PatternMatch.cpp:0:0
 #7 0x000055b1897a911e mlir::RewriterBase::eraseOp(mlir::Operation*)::'lambda0'(mlir::Operation*)::operator()(mlir::Operation*) const (.isra.0) PatternMatch.cpp:0:0
 #8 0x000055b1897a9d36 mlir::RewriterBase::eraseOp(mlir::Operation*) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x45a4d36)
 #9 0x000055b1897a9c09 mlir::RewriterBase::eraseBlock(mlir::Block*) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x45a4c09)
#10 0x000055b18965cdbb mlir::eraseUnreachableBlocks(mlir::RewriterBase&, llvm::MutableArrayRef<mlir::Region>) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x4457dbb)
#11 0x000055b18966535a mlir::simplifyRegions(mlir::RewriterBase&, llvm::MutableArrayRef<mlir::Region>) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x446035a)
#12 0x000055b1896455b1 mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x44405b1)
#13 0x000055b1895adcda (anonymous namespace)::Canonicalizer::runOnOperation() Canonicalizer.cpp:0:0
#14 0x000055b18958e85e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x438985e)
#15 0x000055b18958ed3a mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x4389d3a)
#16 0x000055b18958f504 mlir::PassManager::run(mlir::Operation*) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x438a504)
#17 0x000055b1895801f3 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#18 0x000055b189581774 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
#19 0x000055b189581924 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
#20 0x000055b18967df14 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) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x4478f14)
#21 0x000055b189579d87 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x4374d87)
#22 0x000055b189581a71 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x437ca71)
#23 0x000055b189581ef6 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x437cef6)
#24 0x000055b1867c05d3 main (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x15bb5d3)
#25 0x00007fd721254083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#26 0x000055b18685993e _start (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x165493e)
Segmentation fault (core dumped)
@github-actions github-actions bot added the mlir label Jan 9, 2024
@joker-eph joker-eph added the good first issue https://github.com/llvm/llvm-project/contribute label Jan 9, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 9, 2024

Hi!

This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:

  1. In the comments of the issue, request for it to be assigned to you.
  2. Fix the issue locally.
  3. Run the test suite locally. Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests.
  4. Create a Git commit.
  5. Run git clang-format HEAD~1 to format your changes.
  6. Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation.

If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.

@llvmbot
Copy link
Member

llvmbot commented Jan 9, 2024

@llvm/issue-subscribers-good-first-issue

Author: anonymousMCS (anonymousMCS)

Similar to https://github.com//issues/74461, but with different content in the unreachable block.

git version: 6e90f13

system: Ubuntu 20.04.6 LTS (Focal Fossa)

reproduced with: mlir-opt --canonicalize a.mlir

a.mlir:

func.func private @<!-- -->func1() {
  %false = arith.constant false
  %c0 = arith.constant 0 : index

  cf.cond_br %false, ^bb1, ^bb2
^bb1:  // pred: ^bb0
  omp.parallel {
    omp.wsloop for  (%arg0) : index = (%c0) to (%c0) step (%c0) {
      %189 = llvm.intr.stacksave : !llvm.ptr
      llvm.br ^bb1
    ^bb1:  // pred: ^bb0
      llvm.br ^bb2
    ^bb2:  // pred: ^bb1
      omp.yield
    }
    omp.terminator
  }
  cf.br ^bb2
^bb2:  // pred: ^bb0
  return
}

trace:

PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /data1/bin-dev/llvm-project/build/bin/mlir-opt --canonicalize a.mlir
 #<!-- -->0 0x000055b186889e4f llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x1684e4f)
 #<!-- -->1 0x000055b186886ea4 SignalHandler(int) Signals.cpp:0:0
 #<!-- -->2 0x00007fd721788420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #<!-- -->3 0x000055b1896c0d6b mlir::SuccessorRange::SuccessorRange(mlir::Block*) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x44bbd6b)
 #<!-- -->4 0x000055b18942f71f llvm::po_iterator&lt;mlir::Block*, llvm::SmallPtrSet&lt;mlir::Block*, 8u&gt;, false, llvm::GraphTraits&lt;mlir::Block*&gt;&gt;::traverseChild() (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x422a71f)
 #<!-- -->5 0x000055b18942fdeb llvm::iterator_range&lt;llvm::po_iterator&lt;mlir::Block*, llvm::SmallPtrSet&lt;llvm::GraphTraits&lt;mlir::Block*&gt;::NodeRef, 8u&gt;, false, llvm::GraphTraits&lt;mlir::Block*&gt;&gt;&gt; llvm::post_order&lt;mlir::Block*&gt;(mlir::Block* const&amp;) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x422adeb)
 #<!-- -->6 0x000055b1897a8feb mlir::RewriterBase::eraseOp(mlir::Operation*)::'lambda0'(mlir::Operation*)::operator()(mlir::Operation*) const (.isra.0) PatternMatch.cpp:0:0
 #<!-- -->7 0x000055b1897a911e mlir::RewriterBase::eraseOp(mlir::Operation*)::'lambda0'(mlir::Operation*)::operator()(mlir::Operation*) const (.isra.0) PatternMatch.cpp:0:0
 #<!-- -->8 0x000055b1897a9d36 mlir::RewriterBase::eraseOp(mlir::Operation*) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x45a4d36)
 #<!-- -->9 0x000055b1897a9c09 mlir::RewriterBase::eraseBlock(mlir::Block*) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x45a4c09)
#<!-- -->10 0x000055b18965cdbb mlir::eraseUnreachableBlocks(mlir::RewriterBase&amp;, llvm::MutableArrayRef&lt;mlir::Region&gt;) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x4457dbb)
#<!-- -->11 0x000055b18966535a mlir::simplifyRegions(mlir::RewriterBase&amp;, llvm::MutableArrayRef&lt;mlir::Region&gt;) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x446035a)
#<!-- -->12 0x000055b1896455b1 mlir::applyPatternsAndFoldGreedily(mlir::Region&amp;, mlir::FrozenRewritePatternSet const&amp;, mlir::GreedyRewriteConfig, bool*) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x44405b1)
#<!-- -->13 0x000055b1895adcda (anonymous namespace)::Canonicalizer::runOnOperation() Canonicalizer.cpp:0:0
#<!-- -->14 0x000055b18958e85e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x438985e)
#<!-- -->15 0x000055b18958ed3a mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&amp;, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x4389d3a)
#<!-- -->16 0x000055b18958f504 mlir::PassManager::run(mlir::Operation*) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x438a504)
#<!-- -->17 0x000055b1895801f3 performActions(llvm::raw_ostream&amp;, std::shared_ptr&lt;llvm::SourceMgr&gt; const&amp;, mlir::MLIRContext*, mlir::MlirOptMainConfig const&amp;) MlirOptMain.cpp:0:0
#<!-- -->18 0x000055b189581774 processBuffer(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, mlir::MlirOptMainConfig const&amp;, mlir::DialectRegistry&amp;, llvm::ThreadPool*) MlirOptMain.cpp:0:0
#<!-- -->19 0x000055b189581924 mlir::LogicalResult llvm::function_ref&lt;mlir::LogicalResult (std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::raw_ostream&amp;)&gt;::callback_fn&lt;mlir::MlirOptMain(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, mlir::DialectRegistry&amp;, mlir::MlirOptMainConfig const&amp;)::'lambda'(std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::raw_ostream&amp;)&gt;(long, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::raw_ostream&amp;) MlirOptMain.cpp:0:0
#<!-- -->20 0x000055b18967df14 mlir::splitAndProcessBuffer(std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::function_ref&lt;mlir::LogicalResult (std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::raw_ostream&amp;)&gt;, llvm::raw_ostream&amp;, bool, bool) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x4478f14)
#<!-- -->21 0x000055b189579d87 mlir::MlirOptMain(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, mlir::DialectRegistry&amp;, mlir::MlirOptMainConfig const&amp;) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x4374d87)
#<!-- -->22 0x000055b189581a71 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&amp;) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x437ca71)
#<!-- -->23 0x000055b189581ef6 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&amp;) (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x437cef6)
#<!-- -->24 0x000055b1867c05d3 main (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x15bb5d3)
#<!-- -->25 0x00007fd721254083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#<!-- -->26 0x000055b18685993e _start (/data1/bin-dev/llvm-project/build/bin/mlir-opt+0x165493e)
Segmentation fault (core dumped)

@EugeneZelenko EugeneZelenko added the crash Prefer [crash-on-valid] or [crash-on-invalid] label Jan 9, 2024
@ranjanmangla1
Copy link

I am new to LLVM would love to take this issue!

@EugeneZelenko
Copy link
Contributor

@ranjanmangla1: Just prepare pull request and mention it on this page.

@ranjanmangla1
Copy link

ok, thanks @EugeneZelenko . Working on this issue & will send a pr as soon as possible.

@HerrCai0907 HerrCai0907 self-assigned this Feb 29, 2024
HerrCai0907 added a commit to HerrCai0907/llvm-project that referenced this issue Feb 29, 2024
`llvm::post_order(&r.front())` is equal to `r.front().getSuccessor(...)`.
It will visit the succ block of current block. But actually here need to visit all block in this region.
Fixes: llvm#77420.
HerrCai0907 added a commit that referenced this issue Mar 5, 2024
#66771 introduce `llvm::post_order(&r.front())` which is equal to
`r.front().getSuccessor(...)`.
It will visit the succ block of current block. But actually here need to
visit all block of region in reverse order.
Fixes: #77420.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] good first issue https://github.com/llvm/llvm-project/contribute mlir
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants