[llvm] [Support] Consolidate runOnNewStack (NFC) (PR #160816)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 25 23:37:28 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/160816
This patch consolidates two implementations of runOnNewStack with
"if constexpr".
>From fdb626a047a7ee4b6147af81372c1f34e45b4275 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 10 Sep 2025 20:27:23 -0700
Subject: [PATCH] [Support] Consolidate runOnNewStack (NFC)
This patch consolidates two implementations of runOnNewStack with
"if constexpr".
---
llvm/include/llvm/Support/ProgramStack.h | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/llvm/include/llvm/Support/ProgramStack.h b/llvm/include/llvm/Support/ProgramStack.h
index 0dd8235b90c06..13729a2990588 100644
--- a/llvm/include/llvm/Support/ProgramStack.h
+++ b/llvm/include/llvm/Support/ProgramStack.h
@@ -46,17 +46,15 @@ LLVM_ABI unsigned getDefaultStackSize();
LLVM_ABI void runOnNewStack(unsigned StackSize, function_ref<void()> Fn);
template <typename R, typename... Ts>
-std::enable_if_t<!std::is_same_v<R, void>, R>
-runOnNewStack(unsigned StackSize, function_ref<R(Ts...)> Fn, Ts &&...Args) {
- std::optional<R> Ret;
- runOnNewStack(StackSize, [&]() { Ret = Fn(std::forward<Ts>(Args)...); });
- return std::move(*Ret);
-}
-
-template <typename... Ts>
-void runOnNewStack(unsigned StackSize, function_ref<void(Ts...)> Fn,
+auto runOnNewStack(unsigned StackSize, function_ref<R(Ts...)> Fn,
Ts &&...Args) {
- runOnNewStack(StackSize, [&]() { Fn(std::forward<Ts>(Args)...); });
+ if constexpr (std::is_same_v<R, void>) {
+ runOnNewStack(StackSize, [&]() { Fn(std::forward<Ts>(Args)...); });
+ } else {
+ std::optional<R> Ret;
+ runOnNewStack(StackSize, [&]() { Ret = Fn(std::forward<Ts>(Args)...); });
+ return std::move(*Ret);
+ }
}
} // namespace llvm
More information about the llvm-commits
mailing list