[Mlir-commits] [mlir] [MLIR][Func] Return nullptr for empty ResultAttrs (PR #185219)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Mar 7 11:08:07 PST 2026
https://github.com/sweiglbosker created https://github.com/llvm/llvm-project/pull/185219
Fixes #185156
When an empty res_attrs is passed manually, we should still return nullptr to indicate that no results have attributes.
>From ead076bfaff0b7e78baf59c3b91cfc929fe087ea Mon Sep 17 00:00:00 2001
From: Stefan Weigl-Bosker <stefan at s00.xyz>
Date: Sat, 7 Mar 2026 13:57:46 -0500
Subject: [PATCH] [MLIR][Func] Return nullptr for empty ResultAttrs
---
mlir/include/mlir/Interfaces/FunctionInterfaces.td | 7 +++++--
mlir/test/Conversion/FuncToLLVM/convert-funcs.mlir | 7 +++++++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/mlir/include/mlir/Interfaces/FunctionInterfaces.td b/mlir/include/mlir/Interfaces/FunctionInterfaces.td
index 4c8d5b02ed92a..f701e828ed641 100644
--- a/mlir/include/mlir/Interfaces/FunctionInterfaces.td
+++ b/mlir/include/mlir/Interfaces/FunctionInterfaces.td
@@ -490,8 +490,11 @@ def FunctionOpInterface : OpInterface<"FunctionOpInterface", [
}
/// Return an ArrayAttr containing all result attribute dictionaries of this
- /// function, or nullptr if no result have attributes.
- ::mlir::ArrayAttr getAllResultAttrs() { return $_op.getResAttrsAttr(); }
+ /// function, or nullptr if no results have attributes.
+ ::mlir::ArrayAttr getAllResultAttrs() {
+ auto attrs = $_op.getResAttrsAttr();
+ return attrs && !attrs.empty() ? attrs : nullptr;
+ }
/// Return all result attributes of this function.
void getAllResultAttrs(::llvm::SmallVectorImpl<::mlir::DictionaryAttr> &result) {
diff --git a/mlir/test/Conversion/FuncToLLVM/convert-funcs.mlir b/mlir/test/Conversion/FuncToLLVM/convert-funcs.mlir
index bd281620c2918..4cb31f8f92661 100644
--- a/mlir/test/Conversion/FuncToLLVM/convert-funcs.mlir
+++ b/mlir/test/Conversion/FuncToLLVM/convert-funcs.mlir
@@ -96,3 +96,10 @@ func.func private @badllvmlinkage(i32) attributes { "llvm.linkage" = 3 : i64 } /
func.func @variadic_func(%arg0: i32) attributes { "func.varargs" = true, "llvm.emit_c_interface" } {
return
}
+
+// -----
+
+// CHECK-LABEL: llvm.func @empty_res_attrs()
+func.func @empty_res_attrs() attributes {res_attrs = []} {
+ return
+}
More information about the Mlir-commits
mailing list