<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/107807>107807</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir] [sparse_tensor] -lower-sparse-ops-to-foreach crashes in decltype(auto) llvm::cast(const From &) [To = mlir::RankedTensorType, From = mlir::Type]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
axeabc
</td>
</tr>
</table>
<pre>
git version: 0f5033053a3d4
system: `Ubuntu 18.04.6 LTS`
reproduce with: `mlir-opt -lower-sparse-ops-to-foreach a.mlir`
a.mlir:
```
module {
func.func private @tensor_dimtolvl_reduction_maxui(%arg0: tensor<*xi32>, %arg1: tensor<?xi1>) -> index {
%c0 = arith.constant 0 : index
%dim = tensor.dim %arg0, %c0 : tensor<*xi32>
return %dim : index
}
}
```
stack trace:
```
mlir-opt: /data/szy/MLIR/llvm-release/llvm-project/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From &) [To = mlir::RankedTensorType, From = mlir::Type]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible 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: /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt -lower-sparse-ops-to-foreach a.mlir
#0 0x000056450b0d7ff8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10d3ff8)
#1 0x000056450b0d5b0e llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10d1b0e)
#2 0x000056450b0d898d SignalHandler(int) Signals.cpp:0:0
#3 0x00007fa6df673420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x00007fa6decb000b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
#5 0x00007fa6dec8f859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
#6 0x00007fa6dec8f729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
#7 0x00007fa6dec8f729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
#8 0x00007fa6deca0fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#9 0x000056450ceb9cb9 (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x2eb5cb9)
#10 0x0000564510ba4aa1 void llvm::function_ref<void ()>::callback_fn<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&)>)::$_0>(long) PatternApplicator.cpp:0:0
#11 0x0000564510ba175b 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&)>) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x6b9d75b)
#12 0x000056450e24028f (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#13 0x000056450e23cabf mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4238abf)
#14 0x000056450ce9f9bb (anonymous namespace)::LowerSparseOpsToForeachPass::runOnOperation() SparseTensorPasses.cpp:0:0
#15 0x000056450e1c4e26 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41c0e26)
#16 0x000056450e1c5790 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41c1790)
#17 0x000056450e1c7dd2 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41c3dd2)
#18 0x000056450e1c0601 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#19 0x000056450e1c025b 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&)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#20 0x000056450e26cef5 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) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4268ef5)
#21 0x000056450e1bb685 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41b7685)
#22 0x000056450e1bb92f mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41b792f)
#23 0x000056450e1bbc5e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41b7c5e)
#24 0x000056450b0b8c37 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10b4c37)
#25 0x00007fa6dec91083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#26 0x000056450b0b87be _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10b47be)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWV1z4yrS_jXkhooLoe-LXDjO-H2nKqlJJdndSxUCJLODQAsoY59fvwVSbMtJJjPnjPfUflTNOEY03U93PzRtQawVreL8CqTXIL25IIPbaHNFtpzU9KLWbHfVCgefubFCKxAvIWpSFMcojUnMEoBuAFqOn3ZnHe-8CMjQX-pBuQFGxQIliwzePj2CDB1LG94bzQbK4TfhNtOqTgpzqXsHL6X-xs2l7Ymx_FL39tLpy0YbTugGkoWXO9E3PYynoZ8N_-A47jQbJIcgvx7HEDaDogv_AXsjnonjECTIcWW1qZjonJbPsjKcDdQJraqObAcBcAFwSkyLPOBRGMQrgJdbEWMQfwJ4BUeJaC4Rr7ciCgIlvATxJygU49tjPNAvpAiC-AYSI9xmQbWyjigH_cPluGImzUQXxEczizCc4I046LjyLaB7PYa7waiDuhNDIL-ZIrr_chJa6wj9Cp0hlB_C_3YSpvSGbOM1I44AvLa_7QBe391-fgB4LeVzd2m45MTyl2Fv9N85ddMQ4LVQVA6MHx48Dn2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