diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp --- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp @@ -777,18 +777,23 @@ // The name is unimportant as we will overwrite result.attributes. // The core linalg traits must contain the information necessary to pass the // verifier. + llvm::SMLoc attributeLocation = parser.getCurrentLocation(); if (parser.parseAttribute(dictAttr, "_", result.attributes)) return failure(); result.attributes.assign(dictAttr.getValue().begin(), dictAttr.getValue().end()); - // Convert array of string into an array of IteratyType enums. This is needed, - // because tests still use the old format when 'iterator_types' attribute is - // represented as an array of strings. + // Convert array of string into an array of IteratorType enums. This is + // needed, because tests still use the old format when 'iterator_types' + // attribute is represented as an array of strings. // TODO: Remove this conversion once tests are fixed. - ArrayAttr iteratorTypes = - result.attributes.get(getIteratorTypesAttrName(result.name)) - .cast(); + auto iteratorTypes = dyn_cast_or_null( + result.attributes.get(getIteratorTypesAttrName(result.name))); + if (!iteratorTypes) { + return parser.emitError(attributeLocation) + << "expected " << getIteratorTypesAttrName(result.name) + << " array attribute"; + } SmallVector iteratorTypeAttrs; diff --git a/mlir/test/Dialect/Linalg/invalid.mlir b/mlir/test/Dialect/Linalg/invalid.mlir --- a/mlir/test/Dialect/Linalg/invalid.mlir +++ b/mlir/test/Dialect/Linalg/invalid.mlir @@ -725,3 +725,11 @@ dimensions = [1] func.return %bcast : tensor<4x?x16xf32> } + +// ----- + +func.func @missing_iterator_types() { + // expected-error @below {{expected "iterator_types" array attribute}} + linalg.generic {} ins() outs() + return +}