[Mlir-commits] [mlir] [mlir][tblgen] Fix emit diagnostic on property conversion failures (PR #187786)
Levin Dabhi
llvmlistbot at llvm.org
Tue Mar 24 08:47:39 PDT 2026
https://github.com/levindabhi updated https://github.com/llvm/llvm-project/pull/187786
>From f59fe926c2802629d88d01a9fcbd2927599083b2 Mon Sep 17 00:00:00 2001
From: ldabhi <ldabhi at qti.qualcomm.com>
Date: Fri, 20 Mar 2026 21:13:01 +0100
Subject: [PATCH] [mlir][tblgen] Fix emit diagnostic on property conversion
failures
Fixes segfault in inferred-type builder when attribute type is wrong.
---
mlir/test/mlir-tblgen/op-properties.td | 29 +++++++++++++++++++++
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 6 +++--
2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/mlir/test/mlir-tblgen/op-properties.td b/mlir/test/mlir-tblgen/op-properties.td
index cb9bd3dc868fe..1578a8d1e8e29 100644
--- a/mlir/test/mlir-tblgen/op-properties.td
+++ b/mlir/test/mlir-tblgen/op-properties.td
@@ -5,6 +5,7 @@ include "mlir/IR/AttrTypeBase.td"
include "mlir/IR/EnumAttr.td"
include "mlir/IR/OpBase.td"
include "mlir/IR/Properties.td"
+include "mlir/Interfaces/InferTypeOpInterface.td"
def Test_Dialect : Dialect {
let name = "test";
@@ -36,6 +37,12 @@ def OpWithProps : NS_Op<"op_with_props"> {
);
}
+def OpWithPropsAndInferType : NS_Op<"op_with_props_and_infer_type",
+ [InferTypeOpInterface]> {
+ let arguments = (ins BoolProp:$flag);
+ let results = (outs AnyType:$result);
+}
+
/// Check that optional arguments to builders only go at the end.
def OpWithSomeOptionalProperties : NS_Op<"op_with_some_optional_props"> {
let arguments = (ins
@@ -120,6 +127,28 @@ def OpWithOptionalPropsAndAttrs :
// DEFS: hash_value(prop.optional)
// DEFS: hash_value_(prop.value)
+// COM : Check that collective builders populate a diagnostic callback when converting attributes to properties.
+// DEFS-LABEL: void OpWithProps::build(
+// DEFS: if (!attributes.empty()) {
+// DEFS: if (failed(info->setOpPropertiesFromAttribute(odsState.name, properties,
+// DEFS: odsState.attributes.getDictionary(odsState.getContext()),
+// DEFS: [&]() { return ::mlir::emitError(odsState.location); })))
+// DEFS-NEXT: ::llvm::report_fatal_error("Property conversion failed.");
+
+// COM : Check inferred-type collective builders populate a diagnostic callback too.
+// DEFS-LABEL: void OpWithPropsAndInferType::build({{.*}}::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes{{.*}}) {
+// DEFS: if (!attributes.empty()) {
+// DEFS: if (failed(info->setOpPropertiesFromAttribute(odsState.name, properties,
+// DEFS: odsState.attributes.getDictionary(odsState.getContext()),
+// DEFS: [&]() { return ::mlir::emitError(odsState.location); })))
+// DEFS-NEXT: ::llvm::report_fatal_error("Property conversion failed.");
+// DEFS-LABEL: void OpWithPropsAndInferType::build({{.*}}::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes{{.*}}) {
+// DEFS: if (!attributes.empty()) {
+// DEFS: if (failed(info->setOpPropertiesFromAttribute(odsState.name, properties,
+// DEFS: odsState.attributes.getDictionary(odsState.getContext()),
+// DEFS: [&]() { return ::mlir::emitError(odsState.location); })))
+// DEFS-NEXT: ::llvm::report_fatal_error("Property conversion failed.");
+
// -----
// DECL-LABEL: class OpWithSomeOptionalProperties :
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index e93f91bb540c2..6edc694b14353 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -2857,7 +2857,8 @@ void OpEmitter::genInferredTypeCollectiveParamBuilder(
std::optional<::mlir::RegisteredOperationName> info =
{1}.name.getRegisteredInfo();
if (failed(info->setOpPropertiesFromAttribute({1}.name, properties,
- {1}.attributes.getDictionary({1}.getContext()), nullptr)))
+ {1}.attributes.getDictionary({1}.getContext()),
+ [&]() { return ::mlir::emitError({1}.location); })))
::llvm::report_fatal_error("Property conversion failed.");
})",
opClass.getClassName(), builderOpState);
@@ -3150,7 +3151,8 @@ void OpEmitter::genCollectiveParamBuilder(CollectiveBuilderKind kind) {
std::optional<::mlir::RegisteredOperationName> info =
{1}.name.getRegisteredInfo();
if (failed(info->setOpPropertiesFromAttribute({1}.name, properties,
- {1}.attributes.getDictionary({1}.getContext()), nullptr)))
+ {1}.attributes.getDictionary({1}.getContext()),
+ [&]() { return ::mlir::emitError({1}.location); })))
::llvm::report_fatal_error("Property conversion failed.");
})",
opClass.getClassName(), builderOpState);
More information about the Mlir-commits
mailing list