[MLIR][TOSA][fuzzer-found] tosa.slice folding returns a tensor with the wrong type in tosa-to-tensor
Version
git commit hash: c275ebd64bf5b05e36a3a8e8b8daa32ba9a52aac
LLVM/MLIR 24.0.0git, optimized build with assertions.
Bug Description
The following minimal module is accepted without a pass, but tosa-to-tensor aborts while folding a tosa.slice operation. The folder returns a tensor with shape 2x3x4, while the operation declares its result as 1x3x4.
Crash Chain & Root Cause
Crash chain:
`tosa-to-tensor`
→ `Operation::fold()`
→ `checkFoldResultTypes()`
→ assertion `false && "incorrect fold result type"`
The tosa.slice folder returns a value whose type is inconsistent with the declared result type. The conversion pass reaches the generic fold-result type checker, which reports the mismatch and then aborts instead of treating the fold as a failed rewrite.
Steps to Reproduce
Run the following command with the provided reproducer MLIR:
mlir-opt --tosa-to-tensor reproducer.mlir -o /dev/null
The command returns 134 (SIGABRT). Running mlir-opt reproducer.mlir -o /dev/null without a pass returns 0.
Reproducer (reproducer.mlir)
module {
func.func @main(%arg0: tensor<2x3x4xf32>) -> tensor<1x3x4xf32> {
%start = tosa.const_shape values(dense<0> : tensor<3xindex>) : () -> !tosa.shape<3>
%size = tosa.const_shape values(dense<[2, -1, 4]> : tensor<3xindex>) : () -> !tosa.shape<3>
%slice = tosa.slice %arg0, %start, %size : (tensor<2x3x4xf32>, !tosa.shape<3>, !tosa.shape<3>) -> tensor<1x3x4xf32>
return %slice : tensor<1x3x4xf32>
}
}
Stack Dump
issue8_minimal.mlir:5:14: error: 'tosa.slice' op folder produced a value of incorrect type: 'tensor<2x3x4xf32>', expected: 'tensor<1x3x4xf32>'
%slice = tosa.slice %arg0, %start, %size : (tensor<2x3x4xf32>, !tosa.shape<3>, !tosa.shape<3>) -> tensor<1x3x4xf32>
^
issue8_minimal.mlir:5:14: note: see current operation: %2 = "tosa.slice"(%arg0, %0, %1) : (tensor<2x3x4xf32>, !tosa.shape<3>, !tosa.shape<3>) -> tensor<1x3x4xf32>
mlir-opt: /12T/qin/Fuzzing/MLIR_latest_20261004/llvm-project/mlir/lib/IR/Operation.cpp:617: void checkFoldResultTypes(mlir::Operation*, llvm::SmallVectorImpl<mlir::OpFoldResult>&): Assertion `false && "incorrect fold result 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: mlir-opt --tosa-to-tensor issue8_minimal.mlir -o /dev/null
#0 0x0000559d9a15e699 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (mlir-opt+0x1fa0699)
#1 0x0000559d9a15ae9c llvm::sys::RunSignalHandlers() (mlir-opt+0x1f9ce9c)
#2 0x0000559d9a15b006 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007f5e9641e520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007f5e964729bc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007f5e964729bc __pthread_kill_internal ./nptl/pthread_kill.c:78:76
#6 0x00007f5e964729bc pthread_kill ./signal/pthread_kill.c:89:6
#7 0x00007f5e9641e476 gsignal ./signal/raise.c:27:6
#8 0x00007f5e964047f3 abort ./stdlib/abort.c:81:7
#9 0x00007f5e9640471b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007f5e96415e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x0000559da29d4d1c checkFoldResultTypes(mlir::Operation*, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (.part.0) Operation.cpp:0:0
#12 0x0000559da29d4e4c mlir::Operation::fold(llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/lib/mlir-opt+0xa816e4c)
#13 0x0000559da29d52db mlir::Operation::fold(llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/lib/mlir-opt+0xa8172db)
#14 0x0000559da290da67 mlir::OpBuilder::tryFold(mlir::Operation*, llvm::SmallVectorImpl<mlir::Value>&, llvm::SmallVectorImpl<mlir::Operation*>*) DialectConversion.cpp:0:0
#15 0x0000559da25a7f12 (anonymous namespace)::OperationLegalizer::legalizeWithFold(mlir::Operation*) DialectConversion.cpp:0:0
#16 0x0000559da25a8ceb (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*) DialectConversion.cpp:0:0
#17 0x0000559da25a9154 mlir::OperationConverter::convert(mlir::Operation*, bool) (/lib/mlir-opt+0xa3eb154)
#18 0x0000559da25b28e6 mlir::OperationConverter::applyConversion(llvm::ArrayRef<mlir::Operation*>) (/lib/mlir-opt+0xa3f48e6)
#19 0x0000559da25b3f1f applyConversion(...) DialectConversion.cpp:0:0
#20 0x0000559da25b40d6 mlir::applyPartialConversion(...) (/lib/mlir-opt+0xa3f60d6)
#21 0x0000559d9e16f760 (anonymous namespace)::TosaToTensor::runOnOperation() TosaToTensorPass.cpp:0:0
#22 0x0000559da265d449 mlir::detail::OpToOpPassAdaptor::run(...) (/lib/mlir-opt+0xa49f449)
#23 0x0000559da265d7b4 mlir::detail::OpToOpPassAdaptor::runPipeline(...) (/lib/mlir-opt+0xa49f7b4)
#24 0x0000559da265f6f2 mlir::PassManager::runPasses(...) (/lib/mlir-opt+0xa4a16f2)
#25 0x0000559da26606c9 mlir::PassManager::run(...) (/lib/mlir-opt+0xa4a26c9)
#26 0x0000559d9a2249b3 performActions(...) MlirOptMain.cpp:0:0
#27 0x0000559d9a2252de processBuffer(...) MlirOptMain.cpp:0:0
#28 0x0000559d9a225521 llvm::LogicalResult llvm::function_ref<...>::callback_fn(...) MlirOptMain.cpp:0:0
#29 0x0000559da2a2fa2d mlir::splitAndProcessBuffer(...) (/lib/mlir-opt+0xa871a2d)
#30 0x0000559d9a2202da mlir::MlirOptMain(...) (/lib/mlir-opt+0x2067af8)
#31 0x0000559d9a225af8 mlir::MlirOptMain(...) (/lib/mlir-opt+0x2067d54)
#32 0x0000559d9a0d25cc main (/lib/mlir-opt+0x1f145cc)
#33 0x00007f5e96405d90 __libc_start_call_main
#34 0x00007f5e96405e40 __libc_start_main
#35 0x0000559d9a13df35 _start
@llvm/issue-subscribers-mlir
Author: Kirito (Kiritobl)
git commit hash: c275ebd64bf5b05e36a3a8e8b8daa32ba9a52aac
LLVM/MLIR 24.0.0git, optimized build with assertions.
Bug Description
The following minimal module is accepted without a pass, but tosa-to-tensor aborts while folding a tosa.slice operation. The folder returns a tensor with shape 2x3x4, while the operation declares its result as 1x3x4.
Crash Chain & Root Cause
Crash chain:
`tosa-to-tensor`
→ `Operation::fold()`
→ `checkFoldResultTypes()`
→ assertion `false && "incorrect fold result type"`
The tosa.slice folder returns a value whose type is inconsistent with the declared result type. The conversion pass reaches the generic fold-result type checker, which reports the mismatch and then aborts instead of treating the fold as a failed rewrite.
Steps to Reproduce
Run the following command with the provided reproducer MLIR:
mlir-opt --tosa-to-tensor reproducer.mlir -o /dev/null
The command returns 134 (SIGABRT). Running mlir-opt reproducer.mlir -o /dev/null without a pass returns 0.
Reproducer (reproducer.mlir)
module {
func.func @<!-- -->main(%arg0: tensor<2x3x4xf32>) -> tensor<1x3x4xf32> {
%start = tosa.const_shape values(dense<0> : tensor<3xindex>) : () -> !tosa.shape<3>
%size = tosa.const_shape values(dense<[2, -1, 4]> : tensor<3xindex>) : () -> !tosa.shape<3>
%slice = tosa.slice %arg0, %start, %size : (tensor<2x3x4xf32>, !tosa.shape<3>, !tosa.shape<3>) -> tensor<1x3x4xf32>
return %slice : tensor<1x3x4xf32>
}
}
Stack Dump
issue8_minimal.mlir:5:14: error: 'tosa.slice' op folder produced a value of incorrect type: 'tensor<2x3x4xf32>', expected: 'tensor<1x3x4xf32>'
%slice = tosa.slice %arg0, %start, %size : (tensor<2x3x4xf32>, !tosa.shape<3>, !tosa.shape<3>) -> tensor<1x3x4xf32>
^
issue8_minimal.mlir:5:14: note: see current operation: %2 = "tosa.slice"(%arg0, %0, %1) : (tensor<2x3x4xf32>, !tosa.shape<3>, !tosa.shape<3>) -> tensor<1x3x4xf32>
mlir-opt: /12T/qin/Fuzzing/MLIR_latest_20261004/llvm-project/mlir/lib/IR/Operation.cpp:617: void checkFoldResultTypes(mlir::Operation*, llvm::SmallVectorImpl<mlir::OpFoldResult>&): Assertion `false && "incorrect fold result 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: mlir-opt --tosa-to-tensor issue8_minimal.mlir -o /dev/null
#<!-- -->0 0x0000559d9a15e699 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (mlir-opt+0x1fa0699)
#<!-- -->1 0x0000559d9a15ae9c llvm::sys::RunSignalHandlers() (mlir-opt+0x1f9ce9c)
#<!-- -->2 0x0000559d9a15b006 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#<!-- -->3 0x00007f5e9641e520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#<!-- -->4 0x00007f5e964729bc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#<!-- -->5 0x00007f5e964729bc __pthread_kill_internal ./nptl/pthread_kill.c:78:76
#<!-- -->6 0x00007f5e964729bc pthread_kill ./signal/pthread_kill.c:89:6
#<!-- -->7 0x00007f5e9641e476 gsignal ./signal/raise.c:27:6
#<!-- -->8 0x00007f5e964047f3 abort ./stdlib/abort.c:81:7
#<!-- -->9 0x00007f5e9640471b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#<!-- -->10 0x00007f5e96415e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#<!-- -->11 0x0000559da29d4d1c checkFoldResultTypes(mlir::Operation*, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (.part.0) Operation.cpp:0:0
#<!-- -->12 0x0000559da29d4e4c mlir::Operation::fold(llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/lib/mlir-opt+0xa816e4c)
#<!-- -->13 0x0000559da29d52db mlir::Operation::fold(llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/lib/mlir-opt+0xa8172db)
#<!-- -->14 0x0000559da290da67 mlir::OpBuilder::tryFold(mlir::Operation*, llvm::SmallVectorImpl<mlir::Value>&, llvm::SmallVectorImpl<mlir::Operation*>*) DialectConversion.cpp:0:0
#<!-- -->15 0x0000559da25a7f12 (anonymous namespace)::OperationLegalizer::legalizeWithFold(mlir::Operation*) DialectConversion.cpp:0:0
#<!-- -->16 0x0000559da25a8ceb (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*) DialectConversion.cpp:0:0
#<!-- -->17 0x0000559da25a9154 mlir::OperationConverter::convert(mlir::Operation*, bool) (/lib/mlir-opt+0xa3eb154)
#<!-- -->18 0x0000559da25b28e6 mlir::OperationConverter::applyConversion(llvm::ArrayRef<mlir::Operation*>) (/lib/mlir-opt+0xa3f48e6)
#<!-- -->19 0x0000559da25b3f1f applyConversion(...) DialectConversion.cpp:0:0
#<!-- -->20 0x0000559da25b40d6 mlir::applyPartialConversion(...) (/lib/mlir-opt+0xa3f60d6)
#<!-- -->21 0x0000559d9e16f760 (anonymous namespace)::TosaToTensor::runOnOperation() TosaToTensorPass.cpp:0:0
#<!-- -->22 0x0000559da265d449 mlir::detail::OpToOpPassAdaptor::run(...) (/lib/mlir-opt+0xa49f449)
#<!-- -->23 0x0000559da265d7b4 mlir::detail::OpToOpPassAdaptor::runPipeline(...) (/lib/mlir-opt+0xa49f7b4)
#<!-- -->24 0x0000559da265f6f2 mlir::PassManager::runPasses(...) (/lib/mlir-opt+0xa4a16f2)
#<!-- -->25 0x0000559da26606c9 mlir::PassManager::run(...) (/lib/mlir-opt+0xa4a26c9)
#<!-- -->26 0x0000559d9a2249b3 performActions(...) MlirOptMain.cpp:0:0
#<!-- -->27 0x0000559d9a2252de processBuffer(...) MlirOptMain.cpp:0:0
#<!-- -->28 0x0000559d9a225521 llvm::LogicalResult llvm::function_ref<...>::callback_fn(...) MlirOptMain.cpp:0:0
#<!-- -->29 0x0000559da2a2fa2d mlir::splitAndProcessBuffer(...) (/lib/mlir-opt+0xa871a2d)
#<!-- -->30 0x0000559d9a2202da mlir::MlirOptMain(...) (/lib/mlir-opt+0x2067af8)
#<!-- -->31 0x0000559d9a225af8 mlir::MlirOptMain(...) (/lib/mlir-opt+0x2067d54)
#<!-- -->32 0x0000559d9a0d25cc main (/lib/mlir-opt+0x1f145cc)
#<!-- -->33 0x00007f5e96405d90 __libc_start_call_main
#<!-- -->34 0x00007f5e96405e40 __libc_start_main
#<!-- -->35 0x0000559d9a13df35 _start
Did you generate this entire series of problems using a fuzzer?
@HelloWorldU Yes, these issues were found using a fuzzer. The reproducers in the reports have been reduced; they are not the full MLIR inputs originally generated during fuzzing.
This does not seem to be an issue with tosa-to-tensor as stated here, it can be reproduced just running the canoncalizer on the input IR