[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:34 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: None (sweiglbosker)

<details>
<summary>Changes</summary>

Fixes #<!-- -->185156

When an empty res_attrs is passed manually, we should still return nullptr to indicate that no results have attributes.

---
Full diff: https://github.com/llvm/llvm-project/pull/185219.diff


2 Files Affected:

- (modified) mlir/include/mlir/Interfaces/FunctionInterfaces.td (+5-2) 
- (modified) mlir/test/Conversion/FuncToLLVM/convert-funcs.mlir (+7) 


``````````diff
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
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/185219


More information about the Mlir-commits mailing list