[Mlir-commits] [mlir] [MLIR][FuncToLLVM] fix crash when converting functions with empty res_attrs (PR #177137)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Jan 21 03:16:39 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: None (nataliakokoromyti)

<details>
<summary>Changes</summary>

the assertion assert(!arrayAttrs.empty() && "expected array to be non-empty"); can be removed because 
a) empty res_attrs = [] is valid (as shown by test case)
b) argAttrDicts a few lines below accepts empty arrays without assertion
c) the code after the assertion already handles empty correctly:  if (funcOp.getNumResults() == 1)  // Won't execute if 0 

The assertion that resAttrDicts must be non-empty was incorrectly preventing functions with empty res_attrs from being converted. 

fixes #<!-- -->176858

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


2 Files Affected:

- (modified) mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp (-1) 
- (added) mlir/test/Conversion/FuncToLLVM/empty-res-attrs.mlir (+10) 


``````````diff
diff --git a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
index 2220f61ed8a07..dbf186f53764c 100644
--- a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
+++ b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
@@ -386,7 +386,6 @@ FailureOr<LLVM::LLVMFuncOp> mlir::convertFuncOpToLLVMFuncOp(
   // Propagate argument/result attributes to all converted arguments/result
   // obtained after converting a given original argument/result.
   if (ArrayAttr resAttrDicts = funcOp.getAllResultAttrs()) {
-    assert(!resAttrDicts.empty() && "expected array to be non-empty");
     if (funcOp.getNumResults() == 1)
       newFuncOp.setAllResultAttrs(resAttrDicts);
   }
diff --git a/mlir/test/Conversion/FuncToLLVM/empty-res-attrs.mlir b/mlir/test/Conversion/FuncToLLVM/empty-res-attrs.mlir
new file mode 100644
index 0000000000000..0cc4c88979ab0
--- /dev/null
+++ b/mlir/test/Conversion/FuncToLLVM/empty-res-attrs.mlir
@@ -0,0 +1,10 @@
+// RUN: mlir-opt %s -gpu-kernel-outlining --convert-scf-to-cf --convert-gpu-to-nvvm --nvvm-attach-target=chip=sm_75 --gpu-module-to-binary -gpu-to-llvm --convert-func-to-llvm | FileCheck %s
+
+// Test that functions with empty res_attrs don't crash during conversion
+// CHECK-LABEL: llvm.func @main()
+"builtin.module"() ({
+  "func.func"() ({
+    "gpu.barrier"() : () -> ()
+    "func.return"() : () -> ()
+  }) {sym_name = "main", function_type = () -> (), arg_attrs = [], res_attrs = []} : () -> ()
+}) {} : () -> ()

``````````

</details>


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


More information about the Mlir-commits mailing list