[PATCH] D78966: Don't crash on duplicate keys in dictionary attrs.

Sean Silva via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 27 15:40:13 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG15fcdac49819: Don't crash on duplicate keys in dictionary attrs. (authored by silvas).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D78966/new/

https://reviews.llvm.org/D78966

Files:
  mlir/lib/Parser/Parser.cpp
  mlir/test/IR/invalid.mlir


Index: mlir/test/IR/invalid.mlir
===================================================================
--- mlir/test/IR/invalid.mlir
+++ mlir/test/IR/invalid.mlir
@@ -1489,3 +1489,10 @@
   } : () -> ()
   return
 }
+
+// -----
+
+func @duplicate_dictionary_attr_key() {
+  // expected-error @+1 {{duplicate key in dictionary attribute}}
+  "foo.op"() {a, a} : () -> ()
+}
Index: mlir/lib/Parser/Parser.cpp
===================================================================
--- mlir/lib/Parser/Parser.cpp
+++ mlir/lib/Parser/Parser.cpp
@@ -1676,6 +1676,7 @@
   if (parseToken(Token::l_brace, "expected '{' in attribute dictionary"))
     return failure();
 
+  llvm::SmallDenseSet<Identifier> seenKeys;
   auto parseElt = [&]() -> ParseResult {
     // The name of an attribute can either be a bare identifier, or a string.
     Optional<Identifier> nameId;
@@ -1686,6 +1687,8 @@
       nameId = builder.getIdentifier(getTokenSpelling());
     else
       return emitError("expected attribute name");
+    if (!seenKeys.insert(*nameId).second)
+      return emitError("duplicate key in dictionary attribute");
     consumeToken();
 
     // Try to parse the '=' for the attribute value.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78966.260478.patch
Type: text/x-patch
Size: 1185 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200427/45d6c2fc/attachment.bin>


More information about the llvm-commits mailing list