llvm / llvm/llvm-project

[mlir][emitc] `-wrap-emitc-func-in-class` crashes on `emitc.func` declaration without a body

Open
#224,013 1 comment 0 reactions 0 assignees View on GitHub
crash mlir
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

### Description

`mlir-opt` crashes with an assertion failure when running the `--wrap-emitc-func-in-class` pass on an `emitc.func` declaration without a body.
The crash occurs in `WrapFuncInClass::matchAndRewrite` while processing a private emitc.func.

### Tested commit

[3b8ee89](https://github.com/llvm/llvm-project/commit/3b8ee89006f5a228fce75528f8dd80b4229abcc1)

### Test case

```mlir
module {
emitc.func private @foo()
}
```

### Steps to reproduce

```
mlir-opt test.mlir --wrap-emitc-func-in-class
```

### stack trace

```
mlir-opt: /home/workdir/llvm-project-latest/llvm/include/llvm/ADT/ilist_iterator.h:168: reference llvm::ilist_iterator, false, false>::operator*() const [OptionsT = llvm::ilist_detail::node_options, IsReverse = false, IsConst = false]: Assertion `!NodePtr->isKnownSentinel()' 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: ./mlir-opt test.mlir --wrap-emitc-func-in-class
#0 0x000055a5b9bdfd0b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./mlir-opt+0x1fc2d0b)
#1 0x000055a5b9bdcb11 llvm::sys::RunSignalHandlers() (./mlir-opt+0x1fbfb11)
#2 0x000055a5b9be0a3b SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007ffac5a55520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007ffac5aa99fc pthread_kill (/usr/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007ffac5a55476 gsignal (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007ffac5a3b7f3 abort (/usr/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x00007ffac5a3b71b (/usr/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x00007ffac5a4ce96 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x000055a5bb79a41c WrapFuncInClass::matchAndRewrite(mlir::emitc::FuncOp, mlir::PatternRewriter&) const (./mlir-opt+0x3b7d41c)
#10 0x000055a5c1d846c8 void llvm::function_ref::callback_fn, llvm::function_ref, llvm::function_ref)::$_0>(long) PatternApplicator.cpp:0:0
#11 0x000055a5c1d80e2a mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref, llvm::function_ref, llvm::function_ref) (./mlir-opt+0xa163e2a)
#12 0x000055a5c1d7c306 void llvm::function_ref::callback_fn(long) WalkPatternRewriteDriver.cpp:0:0
#13 0x000055a5c1d7b5c9 mlir::walkAndApplyPatterns(mlir::Operation*, mlir::FrozenRewritePatternSet const&, mlir::RewriterBase::Listener*) (./mlir-opt+0xa15e5c9)
#14 0x000055a5bb796f2e mlir::emitc::(anonymous namespace)::WrapFuncInClassPass::runOnOperation() WrapFuncInClass.cpp:0:0
#15 0x000055a5c1ddf3ee mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (./mlir-opt+0xa1c23ee)
#16 0x000055a5c1de0364 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (./mlir-opt+0xa1c3364)
#17 0x000055a5c1de70fa mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (./mlir-opt+0xa1ca0fa)
#18 0x000055a5c1de6a5d mlir::PassManager::run(mlir::Operation*) (./mlir-opt+0xa1c9a5d)
#19 0x000055a5b9c8b58f performActions(llvm::raw_ostream&, std::shared_ptr const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#20 0x000055a5b9c8a761 llvm::LogicalResult llvm::function_ref>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::callback_fn>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_0>(long, std::unique_ptr>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#21 0x000055a5c2139ec6 mlir::splitAndProcessBuffer(std::unique_ptr>, llvm::function_ref>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (./mlir-opt+0xa51cec6)
#22 0x000055a5b9c80ba6 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (./mlir-opt+0x2063ba6)
#23 0x000055a5b9c80f7a mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x2063f7a)
#24 0x000055a5b9c811eb mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x20641eb)
#25 0x000055a5b9bc57cd main (./mlir-opt+0x1fa87cd)
#26 0x00007ffac5a3cd90 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#27 0x00007ffac5a3ce40 __libc_start_main (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#28 0x000055a5b9bc5325 _start (./mlir-opt+0x1fa8325)
Aborted (core dumped)
```

Contributor guide

Open the contributing guide

Research direction

Inspect WrapFuncInClass::matchAndRewrite in WrapFuncInClass.cpp, focusing on how an emitc.func declaration without a body is handled. Run mlir-opt with the provided module and --wrap-emitc-func-in-class to reproduce the assertion. Done means the declaration no longer crashes the pass and the reproducer completes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.