tsan: remove implicit memcpy in MutexSet::Desc::operator=()
authorDmitry Vyukov <dvyukov@google.com>
Thu, 12 Aug 2021 12:47:47 +0000 (14:47 +0200)
committerDmitry Vyukov <dvyukov@google.com>
Thu, 12 Aug 2021 13:10:05 +0000 (15:10 +0200)
The default compiler-generated MutexSet::Desc::operator=()
now contains memcpy() call since Desc become bigger.
This fails in debug mode since we call interceptor from within the runtime.
Define own operator=() using internal_memcpy().
This also makes copy ctor necessary, otherwise:
tsan_mutexset.h:33:11: warning: definition of implicit copy constructor for
'Desc' is deprecated because it has a user-declared copy assignment operator
And if we add copy ctor, we also need the default ctor
since it's called by MutexSet ctor.

Depends on D107911.

Reviewed By: melver

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

compiler-rt/lib/tsan/rtl/tsan_mutexset.cpp
compiler-rt/lib/tsan/rtl/tsan_mutexset.h

index d76febf..efc0e41 100644 (file)
 
 namespace __tsan {
 
-const uptr MutexSet::kMaxSize;
-
 MutexSet::MutexSet() {
-  internal_memset(&descs_, 0, sizeof(descs_));
 }
 
 void MutexSet::Add(u64 id, bool write, u64 epoch) {
index 606106f..a448cee 100644 (file)
@@ -21,7 +21,7 @@ class MutexSet {
  public:
   // Holds limited number of mutexes.
   // The oldest mutexes are discarded on overflow.
-  static const uptr kMaxSize = 16;
+  static constexpr uptr kMaxSize = 16;
   struct Desc {
     uptr addr;
     StackID stack_id;
@@ -30,6 +30,13 @@ class MutexSet {
     u32 seq;
     u32 count;
     bool write;
+
+    Desc() { internal_memset(this, 0, sizeof(*this)); }
+    Desc(const Desc& other) { *this = other; }
+    Desc& operator=(const MutexSet::Desc& other) {
+      internal_memcpy(this, &other, sizeof(*this));
+      return *this;
+    }
   };
 
   MutexSet();
@@ -42,11 +49,6 @@ class MutexSet {
   uptr Size() const;
   Desc Get(uptr i) const;
 
-  MutexSet(const MutexSet& other) { *this = other; }
-  void operator=(const MutexSet &other) {
-    internal_memcpy(this, &other, sizeof(*this));
-  }
-
  private:
 #if !SANITIZER_GO
   u32 seq_ = 0;