[Mlir-commits] [mlir] [mlir][Transforms] Add missing check in applyPermutation (PR #102099)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Aug 6 10:13:41 PDT 2024
================
@@ -202,6 +202,9 @@ SmallVector<T> applyPermutation(ArrayRef<T> input,
ArrayRef<int64_t> permutation) {
assert(input.size() == permutation.size() &&
"expected input rank to equal permutation rank");
+ assert(
+ llvm::all_of(permutation, [&](size_t s) { return s < input.size(); }) &&
+ "permutation must be within input bounds");
----------------
DarshanRamakant wrote:
I feel this check is needed. If you look at the original issue ([https://github.com/llvm/llvm-project/issues/99513]) there was a crash with cryptic assertion fail. This is happening because of the way permutation range is constructed :
` auto permutationRange = llvm::map_range(
llvm::seq<unsigned>(0, input.size()),
[&](int64_t idx) -> T { return input[permutation[idx]]; });`
We want to make sure that we are not accessing out of boud while doing "input[permutation[idx]]"
https://github.com/llvm/llvm-project/pull/102099
More information about the Mlir-commits
mailing list