<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/111270>111270</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR][Tensor] --linalg-fold-unit-extent-dims crashes with assertion failure "invalid index for shaped type" in FoldEmptyTensorWithDimOp.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tju-chenyaosuo
</td>
</tr>
</table>
<pre>
git version: eaff3a743406ff1636e6328e1ba1bc66318d53cb
command to reproduce: ```mlir-opt --linalg-fold-unit-extent-dims a.mlir```
a.mlir:
```
func.func @func1() -> index {
%3 = tensor.empty() : tensor<19x15x1xf16>
%idx10 = index.constant 10
%dim_162 = tensor.dim %3, %idx10 : tensor<19x15x1xf16> // index out-of-bounds
return %dim_162 : index
}
```
stack trace:
```
mlir-opt: /data2/src/llvm-project/build/tools/mlir/include/mlir/IR/BuiltinTypeInterfaces.h.inc:242: bool mlir::detail::ShapedTypeTrait<ConcreteType>::isDynamicDim(unsigned int) const [with ConcreteType = mlir::RankedTensorType]: Assertion `idx < getRank() && "invalid index for shaped type"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /data2/src/llvm-project/build/bin/mlir-opt --linalg-fold-unit-extent-dims a.mlir
#0 0x0000557113fa73cf llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data2/src/llvm-project/build/bin/mlir-opt+0x15853cf)
#1 0x0000557113fa4434 SignalHandler(int) Signals.cpp:0:0
#2 0x00007fc8af79e420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#3 0x00007fc8af26b00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
#4 0x00007fc8af24a859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
#5 0x00007fc8af24a729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
#6 0x00007fc8af25bfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#7 0x00005571144f3c8d (/data2/src/llvm-project/build/bin/mlir-opt+0x1ad1c8d)
#8 0x000055711614677d (anonymous namespace)::FoldEmptyTensorWithDimOp::matchAndRewrite(mlir::tensor::DimOp, mlir::PatternRewriter&) const TensorOps.cpp:0:0
#9 0x00005571144ebe2f mlir::detail::OpOrInterfaceRewritePatternBase<mlir::tensor::DimOp>::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const (/data2/src/llvm-project/build/bin/mlir-opt+0x1ac9e2f)
#10 0x000055711a470f10 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>) (/data2/src/llvm-project/build/bin/mlir-opt+0x7a4ef10)
#11 0x00005571172e2e08 (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#12 0x00005571172e5c5b mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/data2/src/llvm-project/build/bin/mlir-opt+0x48c3c5b)
#13 0x0000557114cfbf9c (anonymous namespace)::LinalgFoldUnitExtentDimsPass::runOnOperation() DropUnitDims.cpp:0:0
#14 0x000055711722f351 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data2/src/llvm-project/build/bin/mlir-opt+0x480d351)
#15 0x000055711722f82a mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data2/src/llvm-project/build/bin/mlir-opt+0x480d82a)
#16 0x0000557117230374 mlir::PassManager::run(mlir::Operation*) (/data2/src/llvm-project/build/bin/mlir-opt+0x480e374)
#17 0x000055711722187b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#18 0x0000557117222244 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#19 0x00005571172223f4 llvm::LogicalResult llvm::function_ref<llvm::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 0x0000557117329e3e mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (/data2/src/llvm-project/build/bin/mlir-opt+0x4907e3e)
#21 0x0000557117219c99 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data2/src/llvm-project/build/bin/mlir-opt+0x47f7c99)
#22 0x0000557117222561 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data2/src/llvm-project/build/bin/mlir-opt+0x4800561)
#23 0x0000557117222a26 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data2/src/llvm-project/build/bin/mlir-opt+0x4800a26)
#24 0x0000557113ebeaab main (/data2/src/llvm-project/build/bin/mlir-opt+0x149caab)
#25 0x00007fc8af24c083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#26 0x0000557113f7a5be _start (/data2/src/llvm-project/build/bin/mlir-opt+0x15585be)
Aborted (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWd1P4zoW_2vMi9UqsfP5wENp6e5IMwIBq_tYOfFJ6zuJnbUdbrt__cpOCkmhAzOwd-8uglIlx-frd75sM2PEVgJcovgKxasL1tmd0pf2925W7kAemDKduigUP1xuhcWPoI1QEtEFBlZVlKURjYKkqsKEJpBQkkFYsLAok4SGGY9pWaBghYJF_1mqpmGSY6uwhlYr3pXgeKEk6H-bWuiZai2ezWohWb2dVarms04KO4O9BWlnXDQGs7mjfFo2ljG8clz7p1OiqpPl3H1gFAXuf4hIhkiOZ4heYyE57DFKr3pijBGJKUZ0hS1Io_QcmtYehhVORv8Y0WWY78N4H-6rMEH0erRc8H0YeBae-bxU0lgmLQ4HjRwRF80mTMhYEheNl47IcszmrEgnbI3IerBBdXamqlmhOsnNUR0NttNyKnDRLxicla5e9Vr_aSwrv2OrmUftVcIjgN7_ZM2ZZQSRtdElIuu6fmxmrVa_Q2kRWRedqDkia6tUbRBZe9zIWsiy7jg8P_hyh8j6qhO1FfLh0MIXaUFXrAQz382FLBFdkIg4iYVSNR7gR3TBwTJR99_vd6wF7pY_aCYsosulkqUGC-6Zg8yTCbM6SNaIciUaRLJO-vTgWEjrIPfgYRRf_SHsDo85eOieRd8x-R34g4fKC4hXTsGFMaCtUNKFvOB7jOgSb8E68mNUkQSRBCNChHxkteADoJXS2HgjsHUMCUEkxRUTNfB57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