sanitizer_common: don't use [[no_unique_address]]
authorDmitry Vyukov <dvyukov@google.com>
Fri, 23 Jul 2021 08:41:40 +0000 (10:41 +0200)
committerDmitry Vyukov <dvyukov@google.com>
Fri, 23 Jul 2021 08:55:40 +0000 (10:55 +0200)
https://lab.llvm.org/buildbot#builders/112/builds/7881
https://lab.llvm.org/buildbot#builders/121/builds/9907
https://lab.llvm.org/buildbot#builders/105/builds/12770
../../sanitizer_common/sanitizer_mutex.h:288:38: error:
'no_unique_address' attribute directive ignored [-Werror=attributes]
   [[no_unique_address]] CheckedMutex checked_;

Reviewed By: melver

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

compiler-rt/lib/sanitizer_common/sanitizer_mutex.h

index a78eb4a..cbd1c25 100644 (file)
@@ -149,12 +149,15 @@ class CheckedMutex {
 };
 
 // Reader-writer mutex.
-class MUTEX Mutex {
+// Derive from CheckedMutex for the purposes of EBO.
+// We could make it a field marked with [[no_unique_address]],
+// but this attribute is not supported by some older compilers.
+class MUTEX Mutex : CheckedMutex {
  public:
-  constexpr Mutex(MutexType type = MutexUnchecked) : checked_(type) {}
+  constexpr Mutex(MutexType type = MutexUnchecked) : CheckedMutex(type) {}
 
   void Lock() ACQUIRE() {
-    checked_.Lock();
+    CheckedMutex::Lock();
     u64 reset_mask = ~0ull;
     u64 state = atomic_load_relaxed(&state_);
     const uptr kMaxSpinIters = 1500;
@@ -200,7 +203,7 @@ class MUTEX Mutex {
   }
 
   void Unlock() RELEASE() {
-    checked_.Unlock();
+    CheckedMutex::Unlock();
     bool wake_writer;
     u64 wake_readers;
     u64 new_state;
@@ -229,7 +232,7 @@ class MUTEX Mutex {
   }
 
   void ReadLock() ACQUIRE_SHARED() {
-    checked_.Lock();
+    CheckedMutex::Lock();
     bool locked;
     u64 new_state;
     u64 state = atomic_load_relaxed(&state_);
@@ -250,7 +253,7 @@ class MUTEX Mutex {
   }
 
   void ReadUnlock() RELEASE_SHARED() {
-    checked_.Unlock();
+    CheckedMutex::Unlock();
     bool wake;
     u64 new_state;
     u64 state = atomic_load_relaxed(&state_);
@@ -285,7 +288,6 @@ class MUTEX Mutex {
   }
 
  private:
-  [[no_unique_address]] CheckedMutex checked_;
   atomic_uint64_t state_ = {0};
   Semaphore writers_;
   Semaphore readers_;