[Mlir-commits] [mlir] 298424b - [MLIR] Improve verifier failure error message (#188507)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Mar 26 05:11:10 PDT 2026
Author: Mehdi Amini
Date: 2026-03-26T12:11:04Z
New Revision: 298424bed558f5eb1ab21f7765caad5479fc949b
URL: https://github.com/llvm/llvm-project/commit/298424bed558f5eb1ab21f7765caad5479fc949b
DIFF: https://github.com/llvm/llvm-project/commit/298424bed558f5eb1ab21f7765caad5479fc949b.diff
LOG: [MLIR] Improve verifier failure error message (#188507)
Added:
Modified:
mlir/include/mlir/IR/OpImplementation.h
mlir/test/IR/invalid-custom-print-parse.mlir
Removed:
################################################################################
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
diff erent 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
diff erent 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