[libcxx-commits] [libcxxabi] 3601ee6 - [libcxxabi] Make InitByteGlobalMutex check GetThreadID instead of PlatformThreadID

Daniel McIntosh via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jan 12 14:30:14 PST 2022


Author: Daniel McIntosh
Date: 2022-01-12T17:30:10-05:00
New Revision: 3601ee6cfd7faa7468edca45495234e0116c0a4e

URL: https://github.com/llvm/llvm-project/commit/3601ee6cfd7faa7468edca45495234e0116c0a4e
DIFF: https://github.com/llvm/llvm-project/commit/3601ee6cfd7faa7468edca45495234e0116c0a4e.diff

LOG: [libcxxabi] Make InitByteGlobalMutex check GetThreadID instead of PlatformThreadID

By relying on PlatformSupportsThreadID, InitByteGlobalMutex disregards
the GetThreadID template argument, rendering it useless.

This is the 2nd of 5 changes to overhaul cxa_guard.
See D108343 for what the final result will be.

Depends on D109539

Reviewed By: ldionne, #libc_abi

Differential Revision: https://reviews.llvm.org/D110088

Added: 
    

Modified: 
    libcxxabi/src/cxa_guard_impl.h
    libcxxabi/test/guard_test_basic.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxxabi/src/cxa_guard_impl.h b/libcxxabi/src/cxa_guard_impl.h
index 32dbb18bd396f..d431050ca3a86 100644
--- a/libcxxabi/src/cxa_guard_impl.h
+++ b/libcxxabi/src/cxa_guard_impl.h
@@ -156,8 +156,6 @@ uint32_t PlatformThreadID() {
 constexpr uint32_t (*PlatformThreadID)() = nullptr;
 #endif
 
-constexpr bool PlatformSupportsThreadID() { return +PlatformThreadID != nullptr; }
-
 //===----------------------------------------------------------------------===//
 //                          GuardBase
 //===----------------------------------------------------------------------===//
@@ -289,7 +287,7 @@ struct InitByteGlobalMutex : GuardObject<InitByteGlobalMutex<Mutex, CondVar, glo
   using BaseT::BaseT;
 
   explicit InitByteGlobalMutex(uint32_t* g) : BaseT(g), has_thread_id_support(false) {}
-  explicit InitByteGlobalMutex(uint64_t* g) : BaseT(g), has_thread_id_support(PlatformSupportsThreadID()) {}
+  explicit InitByteGlobalMutex(uint64_t* g) : BaseT(g), has_thread_id_support(GetThreadID != nullptr) {}
 
 public:
   AcquireResult acquire_init_byte() {
@@ -404,12 +402,14 @@ struct InitByteFutex : GuardObject<InitByteFutex<Wait, Wake, GetThreadIDArg>> {
 
   /// ARM Constructor
   explicit InitByteFutex(uint32_t* g)
-      : BaseT(g), init_byte(this->init_byte_address), has_thread_id_support(this->thread_id_address && GetThreadIDArg),
+      : BaseT(g), init_byte(this->init_byte_address),
+        has_thread_id_support(this->thread_id_address && GetThreadIDArg != nullptr),
         thread_id(this->thread_id_address) {}
 
   /// Itanium Constructor
   explicit InitByteFutex(uint64_t* g)
-      : BaseT(g), init_byte(this->init_byte_address), has_thread_id_support(this->thread_id_address && GetThreadIDArg),
+      : BaseT(g), init_byte(this->init_byte_address),
+        has_thread_id_support(this->thread_id_address && GetThreadIDArg != nullptr),
         thread_id(this->thread_id_address) {}
 
 public:

diff  --git a/libcxxabi/test/guard_test_basic.pass.cpp b/libcxxabi/test/guard_test_basic.pass.cpp
index b97aeb226d97a..588069bb3759a 100644
--- a/libcxxabi/test/guard_test_basic.pass.cpp
+++ b/libcxxabi/test/guard_test_basic.pass.cpp
@@ -12,9 +12,10 @@
 #include "../src/cxa_guard_impl.h"
 #include <cassert>
 
-// Disable GCC warning about tautological comparison of a function's address
-#if defined(__GNUC__) && !defined(__clang__)
-# pragma GCC diagnostic ignored "-Waddress"
+#if defined(__clang__)
+#  pragma clang diagnostic ignored "-Wtautological-pointer-compare"
+#elif defined(__GNUC__)
+#  pragma GCC diagnostic ignored "-Waddress"
 #endif
 
 using namespace __cxxabiv1;
@@ -135,7 +136,7 @@ int main(int, char**) {
 #if (defined(__APPLE__) || defined(__linux__))  && !defined(_LIBCXXABI_HAS_NO_THREADS)
     assert(PlatformThreadID);
 #endif
-    if (PlatformSupportsThreadID()) {
+    if (PlatformThreadID != nullptr) {
       assert(PlatformThreadID() != 0);
       assert(PlatformThreadID() == PlatformThreadID());
     }


        


More information about the libcxx-commits mailing list