Fix crash in MLIR opaque attribute parser

An assertion is triggered when the dialect is malformed.

Differential Revision: https://reviews.llvm.org/D117709
This commit is contained in:
Mehdi Amini 2022-01-19 19:44:13 +00:00
parent 24bc072edb
commit 4b12f4b2b1
2 changed files with 7 additions and 1 deletions

View File

@ -833,6 +833,7 @@ Attribute Parser::parseDenseElementsAttr(Type attrType) {
/// Parse an opaque elements attribute.
Attribute Parser::parseOpaqueElementsAttr(Type attrType) {
llvm::SMLoc loc = getToken().getLoc();
consumeToken(Token::kw_opaque);
if (parseToken(Token::less, "expected '<' after 'opaque'"))
return nullptr;
@ -857,7 +858,8 @@ Attribute Parser::parseOpaqueElementsAttr(Type attrType) {
std::string data;
if (parseElementAttrHexValues(*this, hexTok, data))
return nullptr;
return OpaqueElementsAttr::get(builder.getStringAttr(name), type, data);
return getChecked<OpaqueElementsAttr>(loc, builder.getStringAttr(name), type,
data);
}
/// Shaped type for elements attribute.

View File

@ -645,3 +645,7 @@ func @erroneous_fields() {
return
}
// -----
// expected-error @+1 {{invalid dialect namespace '"string with space"'}}
#invalid_dialect = opaque<"string with space", "0xDEADBEEF"> : tensor<100xi32>