forked from OSchip/llvm-project
Don't crash on duplicate keys in dictionary attrs.
Differential Revision: https://reviews.llvm.org/D78966
This commit is contained in:
parent
4d40d66402
commit
15fcdac498
|
@ -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.
|
||||
|
|
|
@ -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} : () -> ()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue