[Mlir-commits] [mlir] [mlir] Fix distinct attr mismatch error reporting (PR #68938)
Jacques Pienaar
llvmlistbot at llvm.org
Thu Oct 12 16:57:04 PDT 2023
https://github.com/jpienaar created https://github.com/llvm/llvm-project/pull/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.
>From 5fc64beafde86d414a6203a723c30ca8f875c4f1 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar <jpienaar at google.com>
Date: Thu, 12 Oct 2023 16:48:12 -0700
Subject: [PATCH] [mlir] Fix distinct attr mismatch error reporting
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.
---
mlir/lib/AsmParser/AttributeParser.cpp | 3 ++-
mlir/test/IR/invalid-builtin-attributes.mlir | 2 ++
2 files changed, 4 insertions(+), 1 deletion(-)
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 at below {{referenced attribute does not match previous definition: 42 : i32}}
#attr1 = distinct[0]<43 : i32>
+
+// -----
More information about the Mlir-commits
mailing list