[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:39:46 PDT 2020
silvas updated this revision to Diff 260473.
silvas added a comment.
Update name.
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.260473.patch
Type: text/x-patch
Size: 1185 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200427/9166ebff/attachment.bin>
More information about the llvm-commits
mailing list