[lld] [lld] lld::makeThreadLocal: omit `thread_local` when threads disabled (PR #72057)

Keith Winstein via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 12 09:46:36 PST 2023


https://github.com/keithw updated https://github.com/llvm/llvm-project/pull/72057

>From 3c34949b4a0c7ec19eac52bd652cd80e9e7b8bfc Mon Sep 17 00:00:00 2001
From: Keith Winstein <keithw at cs.stanford.edu>
Date: Sun, 12 Nov 2023 09:20:11 -0800
Subject: [PATCH 1/2] [lld] lld::makeThreadLocal: omit thread_local when
 threads disabled

---
 lld/include/lld/Common/Memory.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lld/include/lld/Common/Memory.h b/lld/include/lld/Common/Memory.h
index c7612a08c6b00db..23e8737bcc207be 100644
--- a/lld/include/lld/Common/Memory.h
+++ b/lld/include/lld/Common/Memory.h
@@ -65,7 +65,11 @@ template <typename T, typename... U> T *make(U &&... args) {
 template <typename T>
 inline llvm::SpecificBumpPtrAllocator<T> &
 getSpecificAllocSingletonThreadLocal() {
+  #if LLVM_ENABLE_THREADS
   thread_local SpecificAlloc<T> instance;
+  #else
+  static SpecificAlloc<T> instance;
+  #endif
   return instance.alloc;
 }
 

>From b5a99daa11409d0741278f2853487a13e4f088f6 Mon Sep 17 00:00:00 2001
From: Keith Winstein <keithw at cs.stanford.edu>
Date: Sun, 12 Nov 2023 09:45:24 -0800
Subject: [PATCH 2/2] Fix formatting

---
 lld/include/lld/Common/Memory.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lld/include/lld/Common/Memory.h b/lld/include/lld/Common/Memory.h
index 23e8737bcc207be..412fe88da03cff8 100644
--- a/lld/include/lld/Common/Memory.h
+++ b/lld/include/lld/Common/Memory.h
@@ -65,11 +65,11 @@ template <typename T, typename... U> T *make(U &&... args) {
 template <typename T>
 inline llvm::SpecificBumpPtrAllocator<T> &
 getSpecificAllocSingletonThreadLocal() {
-  #if LLVM_ENABLE_THREADS
+#if LLVM_ENABLE_THREADS
   thread_local SpecificAlloc<T> instance;
-  #else
+#else
   static SpecificAlloc<T> instance;
-  #endif
+#endif
   return instance.alloc;
 }
 



More information about the llvm-commits mailing list