[Mlir-commits] [mlir] Fix #177829 mlir-opt --convert-vector-to-llvm crashes on vector.insert with out-of-bounds index (PR #179116)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Feb 1 08:45:55 PST 2026
https://github.com/rishabhmadan19 updated https://github.com/llvm/llvm-project/pull/179116
>From 80433044369e94ce304bdf65376975816a592537 Mon Sep 17 00:00:00 2001
From: rishabhmadan19 <rishabhkec at gmail.com>
Date: Sun, 1 Feb 2026 21:08:38 +0530
Subject: [PATCH 1/2] Fix #177829 mlir-opt --convert-vector-to-llvm crashes on
vector.insert with out-of-bounds index
---
.../VectorToLLVM/ConvertVectorToLLVM.cpp | 21 +++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
index 05d541fe80356..b404260be27b6 100644
--- a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
+++ b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
@@ -1237,6 +1237,27 @@ class VectorInsertOpConversion
ArrayRef<OpFoldResult> positionOf1DVectorWithinAggregate(
positionVec.begin(),
insertIntoInnermostDim ? positionVec.size() - 1 : positionVec.size());
+
+ if (isNestedAggregate) {
+ std::optional<SmallVector<int64_t>> maybeAggPos;
+ maybeAggPos =
+ mlir::getConstantIntValues(positionOf1DVectorWithinAggregate);
+ if (!maybeAggPos) {
+ return rewriter.notifyMatchFailure(
+ insertOp, "non-constant aggregate position for extract/insertvalue");
+ }
+
+ // Bounds check against the aggregate dimensions we index into.
+ for (int64_t i = 0, e = static_cast<int64_t>(maybeAggPos->size()); i < e; ++i) {
+ int64_t idx = (*maybeAggPos)[i];
+ int64_t dim = destVectorType.getDimSize(i);
+ if (idx < 0 || idx >= dim) {
+ return rewriter.notifyMatchFailure(insertOp,
+ "out-of-bounds aggregate position");
+ }
+ }
+ }
+
OpFoldResult positionOfScalarWithin1DVector;
if (destVectorType.getRank() == 0) {
// Since the LLVM type converter converts 0D vectors to 1D vectors, we
>From 3a95c6e66ad582b09c72ce537c514ef0a64092c0 Mon Sep 17 00:00:00 2001
From: rishabhmadan19 <rishabhkec at gmail.com>
Date: Sun, 1 Feb 2026 22:10:51 +0530
Subject: [PATCH 2/2] Fix code style in ConvertVectorToLLVM.cpp to appease
clang-format
---
.../Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
index b404260be27b6..a1132a937c14a 100644
--- a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
+++ b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
@@ -1237,23 +1237,25 @@ class VectorInsertOpConversion
ArrayRef<OpFoldResult> positionOf1DVectorWithinAggregate(
positionVec.begin(),
insertIntoInnermostDim ? positionVec.size() - 1 : positionVec.size());
-
+
if (isNestedAggregate) {
std::optional<SmallVector<int64_t>> maybeAggPos;
maybeAggPos =
mlir::getConstantIntValues(positionOf1DVectorWithinAggregate);
if (!maybeAggPos) {
return rewriter.notifyMatchFailure(
- insertOp, "non-constant aggregate position for extract/insertvalue");
+ insertOp,
+ "non-constant aggregate position for extract/insertvalue");
}
// Bounds check against the aggregate dimensions we index into.
- for (int64_t i = 0, e = static_cast<int64_t>(maybeAggPos->size()); i < e; ++i) {
+ for (int64_t i = 0, e = static_cast<int64_t>(maybeAggPos->size()); i < e;
+ ++i) {
int64_t idx = (*maybeAggPos)[i];
int64_t dim = destVectorType.getDimSize(i);
if (idx < 0 || idx >= dim) {
- return rewriter.notifyMatchFailure(insertOp,
- "out-of-bounds aggregate position");
+ return rewriter.notifyMatchFailure(
+ insertOp, "out-of-bounds aggregate position");
}
}
}
More information about the Mlir-commits
mailing list