[Mlir-commits] [mlir] 4b12f4b - Fix crash in MLIR opaque attribute parser

Mehdi Amini llvmlistbot at llvm.org
Wed Jan 19 15:36:03 PST 2022


Author: Mehdi Amini
Date: 2022-01-19T23:35:48Z
New Revision: 4b12f4b2b1a24102658bca9f7c07bed85f95ff9d

URL: https://github.com/llvm/llvm-project/commit/4b12f4b2b1a24102658bca9f7c07bed85f95ff9d
DIFF: https://github.com/llvm/llvm-project/commit/4b12f4b2b1a24102658bca9f7c07bed85f95ff9d.diff

LOG: Fix crash in MLIR opaque attribute parser

An assertion is triggered when the dialect is malformed.

Differential Revision: https://reviews.llvm.org/D117709

Added: 
    

Modified: 
    mlir/lib/Parser/AttributeParser.cpp
    mlir/test/IR/attribute.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Parser/AttributeParser.cpp b/mlir/lib/Parser/AttributeParser.cpp
index d7087de8aad90..9807443c7066b 100644
--- a/mlir/lib/Parser/AttributeParser.cpp
+++ b/mlir/lib/Parser/AttributeParser.cpp
@@ -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.

diff  --git a/mlir/test/IR/attribute.mlir b/mlir/test/IR/attribute.mlir
index 63c05c0cd057b..5da93acb80ffb 100644
--- a/mlir/test/IR/attribute.mlir
+++ b/mlir/test/IR/attribute.mlir
@@ -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>


        


More information about the Mlir-commits mailing list