Skip to content

Commit 16ce990

Browse files
[mlir][Transforms] Add missing check in applyPermutation
The applyPermutation() utility should make sure that the permutation numbers are within the size of the input array. Otherwise it will cause a cryptic array out of bound assertion later.
1 parent 1745c8e commit 16ce990

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

mlir/include/mlir/Dialect/Utils/IndexingUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ SmallVector<T> applyPermutation(ArrayRef<T> input,
202202
ArrayRef<int64_t> permutation) {
203203
assert(input.size() == permutation.size() &&
204204
"expected input rank to equal permutation rank");
205+
assert(
206+
llvm::all_of(permutation, [&](size_t s) { return s < input.size(); }) &&
207+
"permutation must be within input bounds");
205208
auto permutationRange = llvm::map_range(
206209
llvm::seq<unsigned>(0, input.size()),
207210
[&](int64_t idx) -> T { return input[permutation[idx]]; });
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: not --crash mlir-opt %s --pass-pipeline="builtin.module(func.func(tosa-to-linalg-named))" 2>&1 | FileCheck -check-prefix=CHECK %s
2+
3+
func.func @func1() {
4+
%arg0 = tensor.empty() : tensor<3x4x5xi32>
5+
%1110 = arith.constant dense<[3, 0, 1]> : tensor<3xi32>
6+
%143 = tosa.transpose %arg0, %1110: (tensor<3x4x5xi32>, tensor<3xi32>) -> tensor<3x4x5xi32>
7+
return
8+
}
9+
10+
// CHECK: permutation must be within input bounds

0 commit comments

Comments
 (0)