[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:07:19 PDT 2020


silvas created this revision.
silvas added a reviewer: rriddle.
Herald added subscribers: llvm-commits, Kayjukh, frgossen, grosul1, Joonsoo, liufengdb, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, jpienaar, mehdi_amini.
Herald added 1 blocking reviewer(s): rriddle.
Herald added a project: LLVM.
rriddle requested changes to this revision.
rriddle added inline comments.
This revision now requires changes to proceed.


================
Comment at: mlir/lib/Parser/Parser.cpp:1710
+  llvm::SmallDenseSet<Identifier> uniquifier;
+  for (auto &namedAttr : attributes) {
+    if (!uniquifier.insert(namedAttr.first).second) {
----------------
Do this during parsing above to give better error location and avoid the need to iterate.


Fixes http://llvm.org/PR45704


Repository:
  rG LLVM Github Monorepo

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
@@ -1706,6 +1706,13 @@
   if (parseCommaSeparatedListUntil(Token::r_brace, parseElt))
     return failure();
 
+  llvm::SmallDenseSet<Identifier> uniquifier;
+  for (auto &namedAttr : attributes) {
+    if (!uniquifier.insert(namedAttr.first).second) {
+      return emitError("duplicate key in dictionary attribute");
+    }
+  }
+
   return success();
 }
 


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


More information about the llvm-commits mailing list