llvm / llvm/llvm-project

[mlir] Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.

Open
#205,057 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

git version: 5492d06d4fb99795b3b7247be374cdcb47f5ac03

system: `Ubuntu 18.04.6 LTS`

reproduce with: `mlir-opt -convert-openmp-to-llvm a.mlir`

a.mlir:

```mlir
module {
func.func @dim_of_memref_reshape_undominated(%arg0: memref<*xf32>, %arg1: memref<2xindex>, %arg2: index) -> index {
%reshape = memref.reshape %arg0(%arg1) : (memref<*xf32>, memref<2xindex>) -> memref<*xf32>
%dim = memref.dim %reshape, %arg2 : memref<*xf32>
return %dim : index
}
}

```

stack trace:

```
mlir-opt: /data/szy/MLIR/llvm-release/llvm-project/llvm/include/llvm/Support/Casting.h:560: decltype(auto) llvm::cast(const From &) [To = mlir::MemRefType, From = mlir::BaseMemRefType]: Assertion `isa(Val) && "cast() argument of incompatible type!"' 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: /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt -convert-openmp-to-llvm 34.mlir
#0 0x0000556f509c30f8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x20300f8)
#1 0x0000556f509bff91 llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x202cf91)
#2 0x0000556f509c4216 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007f4a349d5420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x00007f4a3401200b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
#5 0x00007f4a33ff1859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
#6 0x00007f4a33ff1729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
#7 0x00007f4a33ff1729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
#8 0x00007f4a34002fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#9 0x0000556f55aded22 (anonymous namespace)::MemRefReshapeOpLowering::matchAndRewrite(mlir::memref::ReshapeOp, mlir::memref::ReshapeOpAdaptor, mlir::ConversionPatternRewriter&) const MemRefToLLVM.cpp:0:0
#10 0x0000556f55adeed2 llvm::LogicalResult mlir::ConversionPattern::dispatchTo1To1, mlir::memref::ReshapeOp>(mlir::ConvertOpToLLVMPattern const&, mlir::memref::ReshapeOp, mlir::memref::ReshapeOp::GenericAdaptor>, mlir::ConversionPatternRewriter&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x714bed2)
#11 0x0000556f55addada mlir::ConvertOpToLLVMPattern::matchAndRewrite(mlir::Operation*, llvm::ArrayRef, mlir::ConversionPatternRewriter&) const (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x714aada)
#12 0x0000556f592c4a94 mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xa931a94)
#13 0x0000556f59312b5d void llvm::function_ref::callback_fn, llvm::function_ref, llvm::function_ref)::$_0>(long) PatternApplicator.cpp:0:0
#14 0x0000556f5930f4ba mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref, llvm::function_ref, llvm::function_ref) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xa97c4ba)
#15 0x0000556f592c683a (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*) DialectConversion.cpp:0:0
#16 0x0000556f592c5ffc mlir::OperationConverter::convert(mlir::Operation*, bool) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xa932ffc)
#17 0x0000556f592c7360 mlir::OperationConverter::applyConversion(llvm::ArrayRef) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xa934360)
#18 0x0000556f592d5649 void llvm::function_ref::callback_fn, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig, (anonymous namespace)::OpConversionMode)::$_0>(long) DialectConversion.cpp:0:0
#19 0x0000556f592cc777 applyConversion(llvm::ArrayRef, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig, (anonymous namespace)::OpConversionMode) DialectConversion.cpp:0:0
#20 0x0000556f592cc85b mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xa93985b)
#21 0x0000556f528656ec (anonymous namespace)::ConvertOpenMPToLLVMPass::runOnOperation() OpenMPToLLVM.cpp:0:0
#22 0x0000556f5936e502 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xa9db502)
#23 0x0000556f5936f344 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+0xa9dc344)
#24 0x0000556f5937625a mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xa9e325a)
#25 0x0000556f59375b8f mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xa9e2b8f)
#26 0x0000556f50a723d0 performActions(llvm::raw_ostream&, std::shared_ptr const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#27 0x0000556f50a71606 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
#28 0x0000556f596c28a5 mlir::splitAndProcessBuffer(std::unique_ptr>, llvm::function_ref>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xad2f8a5)
#29 0x0000556f50a68666 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x20d5666)
#30 0x0000556f50a68a45 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x20d5a45)
#31 0x0000556f50a68da5 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x20d5da5)
#32 0x0000556f509a8b82 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x2015b82)
#33 0x00007f4a33ff3083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#34 0x0000556f509a86be _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x20156be)
Aborted (core dumped)
```

Contributor guide

Open the contributing guide

Research direction

The crash is in MemRefToLLVM.cpp, in MemRefReshapeOpLowering::matchAndRewrite; start there and inspect how the memref.reshape result is handled for the supplied unranked memref. Run mlir-opt -convert-openmp-to-llvm a.mlir with the reproducer. Done means the command no longer triggers the incompatible-type assertion.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.