[Mlir-commits] [mlir] 07b52b5 - [mlir] fix a crash in linalg.generic parser
Alex Zinenko
llvmlistbot at llvm.org
Tue Apr 11 08:36:05 PDT 2023
Author: Alex Zinenko
Date: 2023-04-11T15:35:58Z
New Revision: 07b52b52beaa7f24b817ee1bb48f5b3d8b212d70
URL: https://github.com/llvm/llvm-project/commit/07b52b52beaa7f24b817ee1bb48f5b3d8b212d70
DIFF: https://github.com/llvm/llvm-project/commit/07b52b52beaa7f24b817ee1bb48f5b3d8b212d70.diff
LOG: [mlir] fix a crash in linalg.generic parser
Report an error when the `iterator_types` attribute is missing.
Reviewed By: nicolasvasilache
Differential Revision: https://reviews.llvm.org/D148015
Added:
Modified:
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
mlir/test/Dialect/Linalg/invalid.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
index ee4d064d55d36..da582a50da307 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
@@ -777,18 +777,23 @@ ParseResult GenericOp::parse(OpAsmParser &parser, OperationState &result) {
// 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<ArrayAttr>();
+ auto iteratorTypes = dyn_cast_or_null<ArrayAttr>(
+ result.attributes.get(getIteratorTypesAttrName(result.name)));
+ if (!iteratorTypes) {
+ return parser.emitError(attributeLocation)
+ << "expected " << getIteratorTypesAttrName(result.name)
+ << " array attribute";
+ }
SmallVector<Attribute> iteratorTypeAttrs;
diff --git a/mlir/test/Dialect/Linalg/invalid.mlir b/mlir/test/Dialect/Linalg/invalid.mlir
index 03540be889905..af3dc662e181e 100644
--- a/mlir/test/Dialect/Linalg/invalid.mlir
+++ b/mlir/test/Dialect/Linalg/invalid.mlir
@@ -725,3 +725,11 @@ func.func @broadcast_size_1_extension_not_supported(
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
+}
More information about the Mlir-commits
mailing list