Skip to content

Commit 0e963b9

Browse files
aartbiktensorflower-gardener
authored andcommitted
[VectorOps] Fix off-by-one error in insert/extract validation
PiperOrigin-RevId: 284652653
1 parent 3f9744a commit 0e963b9

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

mlir/lib/Dialect/VectorOps/VectorOps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ static LogicalResult verify(vector::ExtractOp op) {
403403
for (auto en : llvm::enumerate(positionAttr)) {
404404
auto attr = en.value().dyn_cast<IntegerAttr>();
405405
if (!attr || attr.getInt() < 0 ||
406-
attr.getInt() > op.getVectorType().getDimSize(en.index()))
406+
attr.getInt() >= op.getVectorType().getDimSize(en.index()))
407407
return op.emitOpError("expected position attribute #")
408408
<< (en.index() + 1)
409409
<< " to be a non-negative integer smaller than the corresponding "
@@ -517,7 +517,7 @@ static LogicalResult verify(InsertOp op) {
517517
for (auto en : llvm::enumerate(positionAttr)) {
518518
auto attr = en.value().dyn_cast<IntegerAttr>();
519519
if (!attr || attr.getInt() < 0 ||
520-
attr.getInt() > destVectorType.getDimSize(en.index()))
520+
attr.getInt() >= destVectorType.getDimSize(en.index()))
521521
return op.emitOpError("expected position attribute #")
522522
<< (en.index() + 1)
523523
<< " to be a non-negative integer smaller than the corresponding "

mlir/test/Dialect/VectorOps/invalid.mlir

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ func @extract_position_overflow(%arg0: vector<4x8x16xf32>) {
6666

6767
// -----
6868

69+
func @extract_precise_position_overflow(%arg0: vector<4x8x16xf32>) {
70+
// expected-error@+1 {{expected position attribute #3 to be a non-negative integer smaller than the corresponding vector dimension}}
71+
%1 = vector.extract %arg0[3 : i32, 7 : i32, 16 : i32] : vector<4x8x16xf32>
72+
}
73+
74+
// -----
75+
6976
func @extract_position_overflow(%arg0: vector<4x8x16xf32>) {
7077
// expected-error@+1 {{expected position attribute #3 to be a non-negative integer smaller than the corresponding vector dimension}}
7178
%1 = vector.extract %arg0[0 : i32, 0 : i32, -1 : i32] : vector<4x8x16xf32>
@@ -108,6 +115,13 @@ func @insert_position_overflow(%a: f32, %b: vector<4x8x16xf32>) {
108115

109116
// -----
110117

118+
func @insert_precise_position_overflow(%a: f32, %b: vector<4x8x16xf32>) {
119+
// expected-error@+1 {{expected position attribute #1 to be a non-negative integer smaller than the corresponding dest vector dimension}}
120+
%1 = vector.insert %a, %b[4 : i32, 7 : i32, 15 : i32] : f32 into vector<4x8x16xf32>
121+
}
122+
123+
// -----
124+
111125
func @outerproduct_num_operands(%arg0: f32) {
112126
// expected-error@+1 {{expected at least 2 operands}}
113127
%1 = vector.outerproduct %arg0 : f32, f32

0 commit comments

Comments
 (0)