[Mlir-commits] [mlir] [mlir] Fix distinct attr mismatch error reporting (PR #68938)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Oct 12 16:58:10 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Jacques Pienaar (jpienaar)
<details>
<summary>Changes</summary>
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
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>
+
+// -----
``````````
</details>
https://github.com/llvm/llvm-project/pull/68938
More information about the Mlir-commits
mailing list