Skip to content

Commit 7230796

Browse files
authored
[mlir] Fix distinct attr mismatch error reporting (llvm#68938)
Previously the error reported location would not be where expected. E.g., it would fail in the existing test if it wasn't the last in the file.
1 parent 8e2bd05 commit 7230796

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

mlir/lib/AsmParser/AttributeParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,7 @@ Attribute Parser::parseStridedLayoutAttr() {
12251225
/// `[` integer-literal `]<` attribute-value `>`
12261226
///
12271227
Attribute Parser::parseDistinctAttr(Type type) {
1228+
SMLoc loc = getToken().getLoc();
12281229
consumeToken(Token::kw_distinct);
12291230
if (parseToken(Token::l_square, "expected '[' after 'distinct'"))
12301231
return {};
@@ -1269,7 +1270,7 @@ Attribute Parser::parseDistinctAttr(Type type) {
12691270
DistinctAttr distinctAttr = DistinctAttr::create(referencedAttr);
12701271
it = distinctAttrs.try_emplace(*value, distinctAttr).first;
12711272
} else if (it->getSecond().getReferencedAttr() != referencedAttr) {
1272-
emitError("referenced attribute does not match previous definition: ")
1273+
emitError(loc, "referenced attribute does not match previous definition: ")
12731274
<< it->getSecond().getReferencedAttr();
12741275
return {};
12751276
}

mlir/test/IR/invalid-builtin-attributes.mlir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,3 +587,5 @@ func.func @duplicate_dictionary_attr_key() {
587587
#attr = distinct[0]<42 : i32>
588588
// expected-error@below {{referenced attribute does not match previous definition: 42 : i32}}
589589
#attr1 = distinct[0]<43 : i32>
590+
591+
// -----

0 commit comments

Comments
 (0)