[Mlir-commits] [mlir] [mlir][lR] Add Check For Functions with Zero Results in "test-func-erase-result" Pass (PR #127941)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Feb 19 18:19:12 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Ayokunle Amodu (ayokunle321)

<details>
<summary>Changes</summary>

Fixes #<!-- -->119353. 

The pass tries to erase the result of a function with zero results which leads to an assertion error - so I added a check to ensure that a function is skipped if it has no results.

Not really sure how to write the test for this as I don't really understand how the tests in `test-func-erase-result.mlir` work. Also note that the functions that caused the crash (included in the issue mentioned above) are with declarations.


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


1 Files Affected:

- (modified) mlir/test/lib/IR/TestFunc.cpp (+2) 


``````````diff
diff --git a/mlir/test/lib/IR/TestFunc.cpp b/mlir/test/lib/IR/TestFunc.cpp
index 2ade47249863c..2a367e31ac3d4 100644
--- a/mlir/test/lib/IR/TestFunc.cpp
+++ b/mlir/test/lib/IR/TestFunc.cpp
@@ -118,6 +118,8 @@ struct TestFuncEraseResult
     auto module = getOperation();
 
     for (auto func : module.getOps<FunctionOpInterface>()) {
+      if (!func.getNumResults())
+        continue;
       BitVector indicesToErase(func.getNumResults());
       for (auto resultIndex : llvm::seq<int>(0, func.getNumResults()))
         if (func.getResultAttr(resultIndex, "test.erase_this_result"))

``````````

</details>


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


More information about the Mlir-commits mailing list