[llvm] [GlobalOpt] Fix unreachable ifunc globalopt crash (#157332) (PR #157593)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 8 19:49:25 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Justin Riddell (Arghnews)
<details>
<summary>Changes</summary>
Also fixes (#<!-- -->131488)
Unreachable case is triggering `Callees.empty()` assert. Since this was [originally ](https://github.com/llvm/llvm-project/pull/87939/commits/02bd5a7013c558f1e5220fc89bafa68f40276549#diff-06aba0dac2a263dc14297a15655291d5506b760f54a736385bcf3208f83df843R2524) a `continue` anyway, have applied that as a fix and added a test case
---
Full diff: https://github.com/llvm/llvm-project/pull/157593.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/IPO/GlobalOpt.cpp (+2-1)
- (added) llvm/test/Transforms/GlobalOpt/resolve-indirect-ifunc.ll (+11)
``````````diff
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index d7edd1288309b..f88d51f443bcf 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -2551,7 +2551,8 @@ static bool OptimizeNonTrivialIFuncs(
}))
continue;
- assert(!Callees.empty() && "Expecting successful collection of versions");
+ if (Callees.empty())
+ continue;
LLVM_DEBUG(dbgs() << "Statically resolving calls to function "
<< Resolver->getName() << "\n");
diff --git a/llvm/test/Transforms/GlobalOpt/resolve-indirect-ifunc.ll b/llvm/test/Transforms/GlobalOpt/resolve-indirect-ifunc.ll
new file mode 100644
index 0000000000000..1f944a7bde19b
--- /dev/null
+++ b/llvm/test/Transforms/GlobalOpt/resolve-indirect-ifunc.ll
@@ -0,0 +1,11 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt --passes=globalopt -o - -S < %s | FileCheck %s
+
+define ptr @f1() partition "part1" {
+; CHECK-LABEL: define ptr @f1() partition "part1" {
+; CHECK-NEXT: unreachable
+;
+ unreachable
+}
+
+ at i1 = ifunc void(), ptr @f1, partition "part2"
``````````
</details>
https://github.com/llvm/llvm-project/pull/157593
More information about the llvm-commits
mailing list