[llvm] [GlobalOpt] Fix unreachable ifunc globalopt crash (#157332) (PR #157593)
Justin Riddell via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 8 19:48:53 PDT 2025
https://github.com/Arghnews created https://github.com/llvm/llvm-project/pull/157593
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
>From 1f439e499d4c6ed334e35cbd689ebb82a0dc760a Mon Sep 17 00:00:00 2001
From: Justin Riddell <arghnews at hotmail.co.uk>
Date: Tue, 9 Sep 2025 03:33:12 +0100
Subject: [PATCH] [GlobalOpt] Fix unreachable ifunc globalopt crash (#157332)
Also fixes (#131488)
---
llvm/lib/Transforms/IPO/GlobalOpt.cpp | 3 ++-
.../Transforms/GlobalOpt/resolve-indirect-ifunc.ll | 11 +++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/Transforms/GlobalOpt/resolve-indirect-ifunc.ll
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"
More information about the llvm-commits
mailing list