Skip to content

Commit 97729fd

Browse files
committed
[mlir][Vector] Fix vector.mask parser for incorrect passthru cases
This MR fixes a crash when parsing an invalid `vector.mask` with a passtru operand.
1 parent 286ab11 commit 97729fd

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

mlir/lib/Dialect/Vector/IR/VectorOps.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6516,9 +6516,15 @@ ParseResult MaskOp::parse(OpAsmParser &parser, OperationState &result) {
65166516
if (parser.resolveOperand(mask, maskType, result.operands))
65176517
return failure();
65186518

6519-
if (parsePassthru.succeeded())
6519+
if (parsePassthru.succeeded()) {
6520+
if (resultTypes.empty())
6521+
return parser.emitError(
6522+
parser.getNameLoc(),
6523+
"expects a result if passthru operand is provided");
6524+
65206525
if (parser.resolveOperand(passthru, resultTypes[0], result.operands))
65216526
return failure();
6527+
}
65226528

65236529
return success();
65246530
}

mlir/test/Dialect/Vector/invalid.mlir

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,24 @@ func.func @vector_mask_0d_mask(%arg0: tensor<2x4xi32>,
17471747

17481748
// -----
17491749

1750+
func.func @vector_mask_empty_passthru_no_return_type(%mask : vector<8xi1>,
1751+
%passthru : vector<8xi32>) {
1752+
// expected-error@+1 {{'vector.mask' expects a result if passthru operand is provided}}
1753+
vector.mask %mask, %passthru { } : vector<8xi1>
1754+
return
1755+
}
1756+
1757+
// -----
1758+
1759+
func.func @vector_mask_empty_passthru_empty_return_type(%mask : vector<8xi1>,
1760+
%passthru : vector<8xi32>) {
1761+
// expected-error@+1 {{'vector.mask' expects a result if passthru operand is provided}}
1762+
vector.mask %mask, %passthru { } : vector<8xi1> -> ()
1763+
return
1764+
}
1765+
1766+
// -----
1767+
17501768
func.func @vector_scalable_insert_unaligned(%subv: vector<4xi32>, %vec: vector<[16]xi32>) {
17511769
// expected-error@+1 {{op failed to verify that position is a multiple of the source length.}}
17521770
%0 = vector.scalable.insert %subv, %vec[2] : vector<4xi32> into vector<[16]xi32>

0 commit comments

Comments
 (0)