Skip to content

Commit bd3f737

Browse files
committed
Fix MLIR parser to actually error out when hitting a parse error on TensorType encoding field
Fixes llvm#67525
1 parent 7aab12e commit bd3f737

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

mlir/lib/AsmParser/TypeParser.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,15 @@ Type Parser::parseTensorType() {
386386
// Parse an optional encoding attribute.
387387
Attribute encoding;
388388
if (consumeIf(Token::comma)) {
389-
encoding = parseAttribute();
390-
if (auto v = dyn_cast_or_null<VerifiableTensorEncoding>(encoding)) {
391-
if (failed(v.verifyEncoding(dimensions, elementType,
392-
[&] { return emitError(); })))
389+
auto parseResult = parseOptionalAttribute(encoding);
390+
if (parseResult.has_value()) {
391+
if (failed(parseResult.value()))
393392
return nullptr;
393+
if (auto v = dyn_cast_or_null<VerifiableTensorEncoding>(encoding)) {
394+
if (failed(v.verifyEncoding(dimensions, elementType,
395+
[&] { return emitError(); })))
396+
return nullptr;
397+
}
394398
}
395399
}
396400

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: not mlir-opt %s
2+
3+
// Check that mlir-opt fails parsing when fed a tensor with an invalid encoding
4+
5+
!type = tensor<256x32xf16, #blocked>

0 commit comments

Comments
 (0)