Don't crash on duplicate keys in dictionary attrs.

Differential Revision: https://reviews.llvm.org/D78966
This commit is contained in:
Sean Silva 2020-04-27 15:21:52 -07:00
parent 4d40d66402
commit 15fcdac498
2 changed files with 10 additions and 0 deletions

View File

@ -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.

View File

@ -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} : () -> ()
}