Skip to content

[mlir] Fix distinct attr mismatch error reporting #68938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2023
Merged

Conversation

jpienaar
Copy link
Member

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.

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.
@jpienaar jpienaar requested a review from gysit October 12, 2023 23:56
@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Oct 12, 2023
@llvmbot
Copy link
Member

llvmbot commented Oct 12, 2023

@llvm/pr-subscribers-mlir-core

@llvm/pr-subscribers-mlir

Author: Jacques Pienaar (jpienaar)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/68938.diff

2 Files Affected:

  • (modified) mlir/lib/AsmParser/AttributeParser.cpp (+2-1)
  • (modified) mlir/test/IR/invalid-builtin-attributes.mlir (+2)
diff --git a/mlir/lib/AsmParser/AttributeParser.cpp b/mlir/lib/AsmParser/AttributeParser.cpp
index b1991ce06f6eab5..450d0b9802c5058 100644
--- a/mlir/lib/AsmParser/AttributeParser.cpp
+++ b/mlir/lib/AsmParser/AttributeParser.cpp
@@ -1225,6 +1225,7 @@ Attribute Parser::parseStridedLayoutAttr() {
 ///                         `[` integer-literal `]<` attribute-value `>`
 ///
 Attribute Parser::parseDistinctAttr(Type type) {
+  SMLoc loc = getToken().getLoc();
   consumeToken(Token::kw_distinct);
   if (parseToken(Token::l_square, "expected '[' after 'distinct'"))
     return {};
@@ -1269,7 +1270,7 @@ Attribute Parser::parseDistinctAttr(Type type) {
     DistinctAttr distinctAttr = DistinctAttr::create(referencedAttr);
     it = distinctAttrs.try_emplace(*value, distinctAttr).first;
   } else if (it->getSecond().getReferencedAttr() != referencedAttr) {
-    emitError("referenced attribute does not match previous definition: ")
+    emitError(loc, "referenced attribute does not match previous definition: ")
         << it->getSecond().getReferencedAttr();
     return {};
   }
diff --git a/mlir/test/IR/invalid-builtin-attributes.mlir b/mlir/test/IR/invalid-builtin-attributes.mlir
index 1ff44605cb7ecde..431c7b12b8f5fe7 100644
--- a/mlir/test/IR/invalid-builtin-attributes.mlir
+++ b/mlir/test/IR/invalid-builtin-attributes.mlir
@@ -587,3 +587,5 @@ func.func @duplicate_dictionary_attr_key() {
 #attr = distinct[0]<42 : i32>
 // expected-error@below {{referenced attribute does not match previous definition: 42 : i32}}
 #attr1 = distinct[0]<43 : i32>
+
+// -----

Copy link
Contributor

@gysit gysit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:core MLIR Core Infrastructure mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants