[PATCH] D72399: [Support] Replace Windows __declspec(thread) with thread_local in LLVM_THREAD_LOCAL

Russell Gallop via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 8 06:53:40 PST 2020


russell.gallop created this revision.
russell.gallop added reviewers: chandlerc, Bigcheese, dblaikie, jordan_rose.
Herald added a subscriber: dexonsmith.
Herald added a project: LLVM.

Windows minimum host tools version is now VS2017 [1], which supports C++11 thread_local so use this for LLVM_THREAD_LOCAL instead of __declspec(thread). According to [2], thread_local is implemented with __declspec(thread) so this should be NFC.

I believe the only host platform that doesn't support C++ thread_local is Apple Clang 6.0.

[1] https://llvm.org/docs/GettingStarted.html#host-c-toolchain-both-compiler-and-standard-library
[2] https://docs.microsoft.com/en-us/cpp/cpp/thread?view=vs-2017


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72399

Files:
  llvm/include/llvm/Support/Compiler.h


Index: llvm/include/llvm/Support/Compiler.h
===================================================================
--- llvm/include/llvm/Support/Compiler.h
+++ llvm/include/llvm/Support/Compiler.h
@@ -506,19 +506,15 @@
 /// extern globals, and static globals.
 ///
 /// This is essentially an extremely restricted analog to C++11's thread_local
-/// support, and uses that when available. However, it falls back on
-/// platform-specific or vendor-provided extensions when necessary. These
-/// extensions don't support many of the C++11 thread_local's features. You
-/// should only use this for PODs that you can statically initialize to
-/// some constant value. In almost all circumstances this is most appropriate
-/// for use with a pointer, integer, or small aggregation of pointers and
-/// integers.
+/// support. It uses thread_local if available, falling back on gcc __thread
+/// if not. __thread doesn't support many of the C++11 thread_local's
+/// features. You should only use this for PODs that you can statically
+/// initialize to some constant value. In almost all circumstances this is most
+/// appropriate for use with a pointer, integer, or small aggregation of
+/// pointers and integers.
 #if LLVM_ENABLE_THREADS
-#if __has_feature(cxx_thread_local)
+#if __has_feature(cxx_thread_local) or defined(_MSC_VER)
 #define LLVM_THREAD_LOCAL thread_local
-#elif defined(_MSC_VER)
-// MSVC supports this with a __declspec.
-#define LLVM_THREAD_LOCAL __declspec(thread)
 #else
 // Clang, GCC, and other compatible compilers used __thread prior to C++11 and
 // we only need the restricted functionality that provides.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72399.236810.patch
Type: text/x-patch
Size: 1632 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200108/012deffa/attachment.bin>


More information about the llvm-commits mailing list