[Mlir-commits] [mlir] [MLIR] Improve verifier failure error message (PR #188507)
Mehdi Amini
llvmlistbot at llvm.org
Thu Mar 26 04:56:23 PDT 2026
https://github.com/joker-eph updated https://github.com/llvm/llvm-project/pull/188507
>From b0756fb16ec79577dc89a7ab840381b7f8a09b6e Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Wed, 25 Mar 2026 08:19:17 -0700
Subject: [PATCH] [MLIR] Improve verifier failure error message
---
mlir/include/mlir/IR/OpImplementation.h | 5 +++--
mlir/test/IR/invalid-custom-print-parse.mlir | 2 +-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h
index 96c8f3d79c5e0..e66f149b6f812 100644
--- a/mlir/include/mlir/IR/OpImplementation.h
+++ b/mlir/include/mlir/IR/OpImplementation.h
@@ -1165,14 +1165,15 @@ class AsmParser {
typename = std::enable_if_t<!llvm::is_one_of<
AttrType, Attribute, ArrayAttr, StringAttr, SymbolRefAttr>::value>>
OptionalParseResult parseOptionalAttribute(AttrType &result, Type type = {}) {
+ llvm::SMLoc loc = getCurrentLocation();
Attribute attr;
OptionalParseResult parseResult = parseOptionalAttribute(attr, type);
if (!parseResult.has_value() || failed(*parseResult))
return parseResult;
result = dyn_cast<AttrType>(attr);
if (!result)
- return emitError(getCurrentLocation())
- << "expected attribute of a different type";
+ return emitError(loc) << "expected attribute of type '" << AttrType::name
+ << "', but found attribute '" << attr << "'";
return success();
}
diff --git a/mlir/test/IR/invalid-custom-print-parse.mlir b/mlir/test/IR/invalid-custom-print-parse.mlir
index 41e8d97e1db49..774af05943817 100644
--- a/mlir/test/IR/invalid-custom-print-parse.mlir
+++ b/mlir/test/IR/invalid-custom-print-parse.mlir
@@ -29,7 +29,7 @@ test.op_with_enum_prop_attr_form <{value = 0 : i32, foo}>
// Test that an integer literal cannot be used where an APFloat is expected.
// parseOptionalAttribute(FloatAttr &) should reject a non-float attribute.
-// expected-error at +2 {{expected attribute of a different type}}
+// expected-error at +2 {{expected attribute of type 'builtin.float', but found attribute '5 : i64'}}
// expected-error at +1 {{failed to parse TestTypeAPFloat parameter}}
func.func private @test_ap_float_wrong_attr_type() -> !test.ap_float<5U0>
More information about the Mlir-commits
mailing list