Skip to content

Commit 99720bb

Browse files
authored
[MLIR][Utils] Fix the overflow issue in computeSuffixProductImpl for 32-bit system. (llvm#140567)
In `int64_t r = strides.size() - 2`, it may cause overflow on 32-bit system when strides.size() is 1, because `strides.size()` is defined as `unsigned int`
1 parent b6dfe4d commit 99720bb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mlir/lib/Dialect/Utils/IndexingUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SmallVector<ExprType> computeSuffixProductImpl(ArrayRef<ExprType> sizes,
2424
if (sizes.empty())
2525
return {};
2626
SmallVector<ExprType> strides(sizes.size(), unit);
27-
for (int64_t r = strides.size() - 2; r >= 0; --r)
27+
for (int64_t r = static_cast<int64_t>(strides.size()) - 2; r >= 0; --r)
2828
strides[r] = strides[r + 1] * sizes[r + 1];
2929
return strides;
3030
}

0 commit comments

Comments
 (0)