[Mlir-commits] [mlir] bd3f737 - Fix MLIR parser to actually error out when hitting a parse error on TensorType encoding field
Mehdi Amini
llvmlistbot at llvm.org
Wed Sep 27 01:14:52 PDT 2023
Author: Mehdi Amini
Date: 2023-09-27T01:14:39-07:00
New Revision: bd3f7376f1586aad43edfbc21f53cd6143237556
URL: https://github.com/llvm/llvm-project/commit/bd3f7376f1586aad43edfbc21f53cd6143237556
DIFF: https://github.com/llvm/llvm-project/commit/bd3f7376f1586aad43edfbc21f53cd6143237556.diff
LOG: Fix MLIR parser to actually error out when hitting a parse error on TensorType encoding field
Fixes #67525
Added:
mlir/test/IR/fail-invalid-tensor-encoding.mlir
Modified:
mlir/lib/AsmParser/TypeParser.cpp
Removed:
################################################################################
diff --git a/mlir/lib/AsmParser/TypeParser.cpp b/mlir/lib/AsmParser/TypeParser.cpp
index 306e850af27bc58..adaefb78172c2ea 100644
--- a/mlir/lib/AsmParser/TypeParser.cpp
+++ b/mlir/lib/AsmParser/TypeParser.cpp
@@ -386,11 +386,15 @@ Type Parser::parseTensorType() {
// Parse an optional encoding attribute.
Attribute encoding;
if (consumeIf(Token::comma)) {
- encoding = parseAttribute();
- if (auto v = dyn_cast_or_null<VerifiableTensorEncoding>(encoding)) {
- if (failed(v.verifyEncoding(dimensions, elementType,
- [&] { return emitError(); })))
+ auto parseResult = parseOptionalAttribute(encoding);
+ if (parseResult.has_value()) {
+ if (failed(parseResult.value()))
return nullptr;
+ if (auto v = dyn_cast_or_null<VerifiableTensorEncoding>(encoding)) {
+ if (failed(v.verifyEncoding(dimensions, elementType,
+ [&] { return emitError(); })))
+ return nullptr;
+ }
}
}
diff --git a/mlir/test/IR/fail-invalid-tensor-encoding.mlir b/mlir/test/IR/fail-invalid-tensor-encoding.mlir
new file mode 100644
index 000000000000000..a5d27038353e06e
--- /dev/null
+++ b/mlir/test/IR/fail-invalid-tensor-encoding.mlir
@@ -0,0 +1,5 @@
+// RUN: not mlir-opt %s
+
+// Check that mlir-opt fails parsing when fed a tensor with an invalid encoding
+
+!type = tensor<256x32xf16, #blocked>
\ No newline at end of file
More information about the Mlir-commits
mailing list