[BUG] type-related(size_t or int) crash in simple matrix multiply example
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 624
- Forks
- 170
- PR merge metrics
- No merged PRs in 30d
Description
# reproduce
Here is the code implement matrix multiply. The keypoint is `#define SIZE_TYPE size_t`. Notes if the `SIZE_TYPE` changed into `int`, the code will not cause error.
compile method:
```
cgeist --resource-dir=$RESOURCE_DIR ./opti.cpp -o out.execm
```
code
```opti.cpp
#include
#define SIZE_TYPE size_t
const int sb = 128;
void mul(double* a, double* b, double* c, SIZE_TYPE n1, SIZE_TYPE n2, SIZE_TYPE n3) {
for(int i=0;igetParentRegion()) && "expected that op has no uses"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /home/xxx/Polygeist/build/bin/cgeist --resource-dir=/usr/lib/llvm-16/lib/clang/16 ./opti.cpp -o out.execm
#0 0x000055d2419ae92d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/xxx/Polygeist/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:11
#1 0x000055d2419aee1b PrintStackTraceSignalHandler(void*) /home/xxx/Polygeist/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
#2 0x000055d2419ace86 llvm::sys::RunSignalHandlers() /home/xxx/Polygeist/llvm-project/llvm/lib/Support/Signals.cpp:105:5
#3 0x000055d2419af5d5 SignalHandler(int) /home/xxx/Polygeist/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
#4 0x000014db38a5afd0 (/lib/x86_64-linux-gnu/libc.so.6+0x3bfd0)
#5 0x000014db38aa9d3c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#6 0x000014db38a5af32 raise ./signal/../sysdeps/posix/raise.c:27:6
#7 0x000014db38a45472 abort ./stdlib/abort.c:81:7
#8 0x000014db38a45395 _nl_load_domain ./intl/loadmsgcat.c:1177:9
#9 0x000014db38a53e32 (/lib/x86_64-linux-gnu/libc.so.6+0x34e32)
#10 0x000055d241f5a23d mlir::RewriterBase::eraseOp(mlir::Operation*)::$_1::operator()(mlir::Operation*) const /home/xxx/Polygeist/llvm-project/mlir/lib/IR/PatternMatch.cpp:326:7
#11 0x000055d241f5a11e mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0::operator()(mlir::Operation*) const /home/xxx/Polygeist/llvm-project/mlir/lib/IR/PatternMatch.cpp:370:3
#12 0x000055d241f59d70 void std::__invoke_impl(std::__invoke_other, mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0&, mlir::Operation*&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/invoke.h:61:7
#13 0x000055d241f59d0d std::enable_if, void>::type std::__invoke_r(mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0&, mlir::Operation*&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/invoke.h:117:5
#14 0x000055d241f59c35 std::_Function_handler::_M_invoke(std::_Any_data const&, mlir::Operation*&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_function.h:290:2
#15 0x000055d241d0805d std::function::operator()(mlir::Operation*) const /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_function.h:591:2
#16 0x000055d241f59f93 mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0::operator()(mlir::Operation*) const /home/xxx/Polygeist/llvm-project/mlir/lib/IR/PatternMatch.cpp:351:30
#17 0x000055d241f59d70 void std::__invoke_impl(std::__invoke_other, mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0&, mlir::Operation*&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/invoke.h:61:7
#18 0x000055d241f59d0d std::enable_if, void>::type std::__invoke_r(mlir::RewriterBase::eraseOp(mlir::Operation*)::$_0&, mlir::Operation*&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/invoke.h:117:5
#19 0x000055d241f59c35 std::_Function_handler::_M_invoke(std::_Any_data const&, mlir::Operation*&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_function.h:290:2
#20 0x000055d241d0805d std::function::operator()(mlir::Operation*) const /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_function.h:591:2
#21 0x000055d241f59120 mlir::RewriterBase::eraseOp(mlir::Operation*) /home/xxx/Polygeist/llvm-project/mlir/lib/IR/PatternMatch.cpp:373:1
#22 0x000055d241f58e0a mlir::RewriterBase::replaceOp(mlir::Operation*, mlir::ValueRange) /home/xxx/Polygeist/llvm-project/mlir/lib/IR/PatternMatch.cpp:282:1
#23 0x000055d2429c4a40 MoveWhileToFor::matchAndRewrite(mlir::scf::WhileOp, mlir::PatternRewriter&) const /home/xxx/Polygeist/lib/polygeist/Passes/CanonicalizeFor.cpp:981:12
#24 0x000055d2428d103b mlir::detail::OpOrInterfaceRewritePatternBase::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const /home/xxx/Polygeist/llvm-project/mlir/include/mlir/IR/PatternMatch.h:330:12
#25 0x000055d2483df576 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref, llvm::function_ref, llvm::function_ref)::$_0::operator()() const /home/xxx/Polygeist/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:206:31
#26 0x000055d2483df3b5 void llvm::function_ref::callback_fn, llvm::function_ref, llvm::function_ref)::$_0>(long) /home/xxx/Polygeist/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:5
#27 0x000055d2406afb69 llvm::function_ref::operator()() const /home/xxx/Polygeist/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:5
#28 0x000055d2483e0d95 void mlir::MLIRContext::executeAction(llvm::function_ref, llvm::ArrayRef, mlir::Pattern const&) /home/xxx/Polygeist/llvm-project/mlir/include/mlir/IR/MLIRContext.h:276:3
#29 0x000055d2483dde57 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref, llvm::function_ref, llvm::function_ref) /home/xxx/Polygeist/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:227:9
#30 0x000055d242e9e4e8 (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() /home/xxx/Polygeist/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:474:17
#31 0x000055d242e9dfc1 (anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) &&::$_2::operator()() const /home/xxx/Polygeist/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:696:30
#32 0x000055d242e9df95 void llvm::function_ref::callback_fn<(anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) &&::$_2>(long) /home/xxx/Polygeist/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:5
#33 0x000055d2406afb69 llvm::function_ref::operator()() const /home/xxx/Polygeist/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:5
#34 0x000055d242e9d715 void mlir::MLIRContext::executeAction<(anonymous namespace)::GreedyPatternRewriteIteration, long&>(llvm::function_ref, llvm::ArrayRef, long&) /home/xxx/Polygeist/llvm-project/mlir/include/mlir/IR/MLIRContext.h:276:3
#35 0x000055d242e9ba15 (anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) && /home/xxx/Polygeist/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:704:3
#36 0x000055d242e9b737 mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) /home/xxx/Polygeist/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:730:47
#37 0x000055d241be8aa5 mlir::applyPatternsAndFoldGreedily(mlir::Operation*, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) /home/xxx/Polygeist/llvm-project/mlir/include/mlir/Transforms/GreedyPatternRewriteDriver.h:123:9
#38 0x000055d2429bb409 (anonymous namespace)::CanonicalizeFor::runOnOperation() /home/xxx/Polygeist/lib/polygeist/Passes/CanonicalizeFor.cpp:2247:9
#39 0x000055d242e120fb mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_1::operator()() const /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:0:17
#40 0x000055d242e12095 void llvm::function_ref::callback_fn(long) /home/xxx/Polygeist/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:5
#41 0x000055d2406afb69 llvm::function_ref::operator()() const /home/xxx/Polygeist/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:5
#42 0x000055d242e14ef5 void mlir::MLIRContext::executeAction(llvm::function_ref, llvm::ArrayRef, mlir::Pass&) /home/xxx/Polygeist/llvm-project/mlir/include/mlir/IR/MLIRContext.h:276:3
#43 0x000055d242e0d843 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:509:17
#44 0x000055d242e0ddc4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:569:16
#45 0x000055d242e0ec1e mlir::detail::OpToOpPassAdaptor::runOnOperationImpl(bool) /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:710:20
#46 0x000055d242e0e4cd mlir::detail::OpToOpPassAdaptor::runOnOperation(bool) /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:693:1
#47 0x000055d242e120e6 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_1::operator()() const /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:501:11
#48 0x000055d242e12095 void llvm::function_ref::callback_fn(long) /home/xxx/Polygeist/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:5
#49 0x000055d2406afb69 llvm::function_ref::operator()() const /home/xxx/Polygeist/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:5
#50 0x000055d242e14ef5 void mlir::MLIRContext::executeAction(llvm::function_ref, llvm::ArrayRef, mlir::Pass&) /home/xxx/Polygeist/llvm-project/mlir/include/mlir/IR/MLIRContext.h:276:3
#51 0x000055d242e0d843 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:509:17
#52 0x000055d242e0ddc4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:569:16
#53 0x000055d242e0f809 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:880:10
#54 0x000055d242e0f732 mlir::PassManager::run(mlir::Operation*) /home/xxx/Polygeist/llvm-project/mlir/lib/Pass/Pass.cpp:860:60
#55 0x000055d23fc6ce53 main /home/xxx/Polygeist/tools/cgeist/driver.cc:688:25
#56 0x000014db38a461ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#57 0x000014db38a46285 call_init ./csu/../csu/libc-start.c:128:20
#58 0x000014db38a46285 __libc_start_main ./csu/../csu/libc-start.c:347:5
#59 0x000055d23fc3f931 _start (/home/xxx/Polygeist/build/bin/cgeist+0x8e2931)
Aborted (core dumped)
```
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the crash with the provided opti.cpp example and cgeist command. Then inspect MoveWhileToFor in lib/polygeist/Passes/CanonicalizeFor.cpp, especially the rewrite around line 981 and the CanonicalizeFor entry point near line 2247. Done means the size_t version no longer triggers the MLIR eraseOp assertion while the int version remains functional.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100