Skip to content

Commit 22a11be

Browse files
authored
[mlir][vector] Fix parser of vector.contract (#133434)
This PR adds a check in the parser to prevent a crash when `vector.contract` lacks the `iterator_types` attribute. Fixes #132886.
1 parent 724f209 commit 22a11be

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,13 @@ ParseResult ContractionOp::parse(OpAsmParser &parser, OperationState &result) {
787787
// because tests still use the old format when 'iterator_types' attribute is
788788
// represented as an array of strings.
789789
// TODO: Remove this conversion once tests are fixed.
790-
ArrayAttr iteratorTypes = llvm::cast<ArrayAttr>(
790+
auto iteratorTypes = dyn_cast_or_null<ArrayAttr>(
791791
result.attributes.get(getIteratorTypesAttrName(result.name)));
792+
if (!iteratorTypes) {
793+
return parser.emitError(loc)
794+
<< "expected " << getIteratorTypesAttrName(result.name)
795+
<< " array attribute";
796+
}
792797

793798
SmallVector<Attribute> iteratorTypeAttrs;
794799

mlir/test/Dialect/Vector/invalid.mlir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,14 @@ func.func @contract_with_dim_unused_by_lhs_and_rhs(%arg0 : vector<1x2xi32>, %arg
10151015

10161016
// -----
10171017

1018+
func.func @contract_missing_iterator_types(%arg0: vector<1x2xi32>, %arg1: vector<2xi32>, %arg2: vector<1xi32>) -> vector<1xi32> {
1019+
// expected-error@+1 {{'vector.contract' expected "iterator_types" array attribute}}
1020+
%0 = vector.contract {} %arg0, %arg1, %arg2 : vector<1x2xi32>, vector<2xi32> into vector<1xi32>
1021+
return %0 : vector<1xi32>
1022+
}
1023+
1024+
// -----
1025+
10181026
func.func @create_mask_0d_no_operands() {
10191027
%c1 = arith.constant 1 : index
10201028
// expected-error@+1 {{must specify exactly one operand for 0-D create_mask}}

0 commit comments

Comments
 (0)