[llvm] 8f9385c - [Support] Consolidate runOnNewStack (NFC) (#160816)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 26 08:44:00 PDT 2025


Author: Kazu Hirata
Date: 2025-09-26T08:43:56-07:00
New Revision: 8f9385c6c9f17f81be08eac9d8f56de612ad184f

URL: https://github.com/llvm/llvm-project/commit/8f9385c6c9f17f81be08eac9d8f56de612ad184f
DIFF: https://github.com/llvm/llvm-project/commit/8f9385c6c9f17f81be08eac9d8f56de612ad184f.diff

LOG: [Support] Consolidate runOnNewStack (NFC) (#160816)

This patch consolidates two implementations of runOnNewStack with
"if constexpr".

Added: 
    

Modified: 
    llvm/include/llvm/Support/ProgramStack.h

Removed: 
    


################################################################################
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