diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -1706,6 +1706,13 @@ if (parseCommaSeparatedListUntil(Token::r_brace, parseElt)) return failure(); + llvm::SmallDenseSet uniquifier; + for (auto &namedAttr : attributes) { + if (!uniquifier.insert(namedAttr.first).second) { + return emitError("duplicate key in dictionary attribute"); + } + } + return success(); } diff --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir --- a/mlir/test/IR/invalid.mlir +++ b/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} : () -> () +}