[Mlir-commits] [mlir] 15fcdac - Don't crash on duplicate keys in dictionary attrs.
Sean Silva
llvmlistbot at llvm.org
Mon Apr 27 15:23:58 PDT 2020
Author: Sean Silva
Date: 2020-04-27T15:23:49-07:00
New Revision: 15fcdac49819a446764be11bc605344a4f03de1c
URL: https://github.com/llvm/llvm-project/commit/15fcdac49819a446764be11bc605344a4f03de1c
DIFF: https://github.com/llvm/llvm-project/commit/15fcdac49819a446764be11bc605344a4f03de1c.diff
LOG: Don't crash on duplicate keys in dictionary attrs.
Differential Revision: https://reviews.llvm.org/D78966
Added:
Modified:
mlir/lib/Parser/Parser.cpp
mlir/test/IR/invalid.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp
index 8ba391de7baf..973b98b841fb 100644
--- a/mlir/lib/Parser/Parser.cpp
+++ b/mlir/lib/Parser/Parser.cpp
@@ -1676,6 +1676,7 @@ Parser::parseAttributeDict(SmallVectorImpl<NamedAttribute> &attributes) {
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 @@ Parser::parseAttributeDict(SmallVectorImpl<NamedAttribute> &attributes) {
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.
diff --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir
index cf7f7eb3152f..96b234834481 100644
--- a/mlir/test/IR/invalid.mlir
+++ b/mlir/test/IR/invalid.mlir
@@ -1489,3 +1489,10 @@ func @really_large_bound() {
} : () -> ()
return
}
+
+// -----
+
+func @duplicate_dictionary_attr_key() {
+ // expected-error @+1 {{duplicate key in dictionary attribute}}
+ "foo.op"() {a, a} : () -> ()
+}
More information about the Mlir-commits
mailing list