Skip to content

Commit b6dfe4d

Browse files
authored
[mlir][Vector] Fix vector.mask parser for incorrect passthru cases (llvm#140319)
This MR fixes a crash when parsing an invalid `vector.mask` with a passtru operand.
1 parent dd0a1c5 commit b6dfe4d

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
@@ -6517,9 +6517,15 @@ ParseResult MaskOp::parse(OpAsmParser &parser, OperationState &result) {
65176517
if (parser.resolveOperand(mask, maskType, result.operands))
65186518
return failure();
65196519

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

65246530
return success();
65256531
}

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)