| Issue |
237496
|
| Summary |
[MLIR][Vector][fuzzer-found] canonicalize aborts in StridedSliceBroadcast with prefix-only slice attributes
|
| Labels |
mlir
|
| Assignees |
|
| Reporter |
Kiritobl
|
#### Version
git commit hash: 982197fad060f461277020c0ca413d93a5f2a8a6
LLVM/MLIR 24.0.0git, optimized build with assertions.
#### Bug Description
`--canonicalize` aborts in `StridedSliceBroadcast` when a `vector.extract_strided_slice` of a `vector.broadcast` specifies slice attributes for only a prefix of the vector dimensions. The input below parses and verifies successfully without the pass. It has been reduced to one broadcast and one strided slice.
The broadcast expands `vector<2x1xf32>` to `vector<2x4xf32>`, and the slice extracts the second row using `offsets = [1], sizes = [1], strides = [1]`. These one-element arrays describe only the first dimension; the trailing dimension is unchanged. The result is `vector<1x4xf32>`.
#### Crash Chain & Root Cause
Crash chain:
```text
`--canonicalize`
→ StridedSliceBroadcast::matchAndRewrite()
→ needsSlice is true because the first source dimension shrinks from 2 to 1
→ offsets and sizes are copied from the one-element slice attributes
→ the rewrite loops over both source dimensions
→ the trailing source dimension has size 1, so it writes offsets[1] and sizes[1]
→ SmallVector::operator[] asserts: idx < size()
```
In `mlir/lib/Dialect/Vector/IR/VectorOps.cpp:4957–4969`, the pattern constructs `offsets` and `sizes` by dropping `rankDiff` entries from the slice attributes, then iterates up to `srcRank`. For this input, `rankDiff` is 0 and `srcRank` is 2, but both arrays contain only one element. When `i` reaches 1, `srcVecType.getDimSize(i) == 1` is true, and `offsets[i] = 0` is already out of bounds; the following `sizes[i] = 1` has the same problem.
`vector.extract_strided_slice` permits its `offsets`, `sizes`, and `strides` arrays to describe only the leading dimensions. The rewrite incorrectly assumes these arrays cover every source dimension. As a control, replacing the attributes with the equivalent full-rank form `offsets = [1, 0], sizes = [1, 4], strides = [1, 1]` allows canonicalization to complete successfully on the same build.
Expected behavior is to canonicalize the valid prefix-only slice while preserving the unchanged trailing dimensions, or decline the rewrite. It must not access past the attribute arrays or abort.
#### Steps to Reproduce
```bash
mlir-opt --canonicalize reproducer.mlir -o /dev/null
```
The process terminates with `SIGABRT` (shell exit status 134). Running `mlir-opt reproducer.mlir -o /dev/null` without the pass succeeds.
#### Reproducer (`reproducer.mlir`)
```mlir
module {
func.func @f(%arg0: vector<2x1xf32>) -> vector<1x4xf32> {
%0 = vector.broadcast %arg0 : vector<2x1xf32> to vector<2x4xf32>
%1 = vector.extract_strided_slice %0 offsets = [1], sizes = [1], strides = [1] : vector<2x4xf32> to vector<1x4xf32>
return %1 : vector<1x4xf32>
}
}
```
#### Stack Dump
The following block is the unmodified stderr from running the command above with this build:
```text
mlir-opt: /12T/qin/Fuzzing/MLIR_latest_20261028/llvm-project/llvm/include/llvm/ADT/SmallVector.h:302: T& llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::operator[](llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type) [with T = long int; <template-parameter-1-2> = void; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::reference = long int&; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type = long unsigned int]: Assertion `idx < size()' 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: /12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt --canonicalize reproducer.mlir -o /dev/null
#0 0x0000555ffc890819 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x1fbb819)
#1 0x0000555ffc88d01c llvm::sys::RunSignalHandlers() (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x1fb801c)
#2 0x0000555ffc88d186 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007fa4f8ca5520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007fa4f8cf99bc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007fa4f8cf99bc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x00007fa4f8cf99bc pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x00007fa4f8ca5476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007fa4f8c8b7f3 abort ./stdlib/abort.c:81:7
#9 0x00007fa4f8c8b71b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007fa4f8c9ce96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x00005560035e2204 (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x8d0d204)
#12 0x0000556004dfa6ac 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&)>)::'lambda'()::operator()() const PatternApplicator.cpp:0:0
#13 0x0000556004dfbd8a 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&)>) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa526d8a)
#14 0x0000556004dc1db3 (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#15 0x0000556004dc45f7 mlir::applyPatternsGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa4ef5f7)
#16 0x0000556004cb2e62 (anonymous namespace)::Canonicalizer::runOnOperation() Canonicalizer.cpp:0:0
#17 0x0000556004e626d9 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa58d6d9)
#18 0x0000556004e629b4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa58d9b4)
#19 0x0000556004e64602 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa58f602)
#20 0x0000556004e655d9 mlir::PassManager::run(mlir::Operation*) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa5905d9)
#21 0x0000555ffc958c69 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#22 0x0000555ffc95a14e processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, mlir::SourceMgrDiagnosticVerifierHandler*, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#23 0x0000555ffc95a391 llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, 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::MemoryBufferRef, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#24 0x00005560051da5ed 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::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0xa9055ed)
#25 0x0000555ffc95415a mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (.part.0) MlirOptMain.cpp:0:0
#26 0x0000555ffc95a9d1 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x20859d1)
#27 0x0000555ffc95ac24 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x2085c24)
#28 0x0000555ffc82b8c7 main (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x1f568c7)
#29 0x00007fa4f8c8cd90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#30 0x00007fa4f8c8ce40 call_init ./csu/../csu/libc-start.c:128:20
#31 0x00007fa4f8c8ce40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#32 0x0000555ffc8700b5 _start (/12T/qin/Fuzzing/MLIR_latest_20261028/install/bin/mlir-opt+0x1f9b0b5)
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs