Skip to content

Commit 3601ee6

Browse files
[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
1 parent e42eeb8 commit 3601ee6

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

libcxxabi/src/cxa_guard_impl.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ uint32_t PlatformThreadID() {
156156
constexpr uint32_t (*PlatformThreadID)() = nullptr;
157157
#endif
158158

159-
constexpr bool PlatformSupportsThreadID() { return +PlatformThreadID != nullptr; }
160-
161159
//===----------------------------------------------------------------------===//
162160
// GuardBase
163161
//===----------------------------------------------------------------------===//
@@ -289,7 +287,7 @@ struct InitByteGlobalMutex : GuardObject<InitByteGlobalMutex<Mutex, CondVar, glo
289287
using BaseT::BaseT;
290288

291289
explicit InitByteGlobalMutex(uint32_t* g) : BaseT(g), has_thread_id_support(false) {}
292-
explicit InitByteGlobalMutex(uint64_t* g) : BaseT(g), has_thread_id_support(PlatformSupportsThreadID()) {}
290+
explicit InitByteGlobalMutex(uint64_t* g) : BaseT(g), has_thread_id_support(GetThreadID != nullptr) {}
293291

294292
public:
295293
AcquireResult acquire_init_byte() {
@@ -404,12 +402,14 @@ struct InitByteFutex : GuardObject<InitByteFutex<Wait, Wake, GetThreadIDArg>> {
404402

405403
/// ARM Constructor
406404
explicit InitByteFutex(uint32_t* g)
407-
: BaseT(g), init_byte(this->init_byte_address), has_thread_id_support(this->thread_id_address && GetThreadIDArg),
405+
: BaseT(g), init_byte(this->init_byte_address),
406+
has_thread_id_support(this->thread_id_address && GetThreadIDArg != nullptr),
408407
thread_id(this->thread_id_address) {}
409408

410409
/// Itanium Constructor
411410
explicit InitByteFutex(uint64_t* g)
412-
: BaseT(g), init_byte(this->init_byte_address), has_thread_id_support(this->thread_id_address && GetThreadIDArg),
411+
: BaseT(g), init_byte(this->init_byte_address),
412+
has_thread_id_support(this->thread_id_address && GetThreadIDArg != nullptr),
413413
thread_id(this->thread_id_address) {}
414414

415415
public:

libcxxabi/test/guard_test_basic.pass.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
#include "../src/cxa_guard_impl.h"
1313
#include <cassert>
1414

15-
// Disable GCC warning about tautological comparison of a function's address
16-
#if defined(__GNUC__) && !defined(__clang__)
17-
# pragma GCC diagnostic ignored "-Waddress"
15+
#if defined(__clang__)
16+
# pragma clang diagnostic ignored "-Wtautological-pointer-compare"
17+
#elif defined(__GNUC__)
18+
# pragma GCC diagnostic ignored "-Waddress"
1819
#endif
1920

2021
using namespace __cxxabiv1;
@@ -135,7 +136,7 @@ int main(int, char**) {
135136
#if (defined(__APPLE__) || defined(__linux__)) && !defined(_LIBCXXABI_HAS_NO_THREADS)
136137
assert(PlatformThreadID);
137138
#endif
138-
if (PlatformSupportsThreadID()) {
139+
if (PlatformThreadID != nullptr) {
139140
assert(PlatformThreadID() != 0);
140141
assert(PlatformThreadID() == PlatformThreadID());
141142
}

0 commit comments

Comments
 (0)