[compiler-rt] 62139c5 - tsan: remove implicit memcpy in MutexSet::Desc::operator=()

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 12 06:10:10 PDT 2021


Author: Dmitry Vyukov
Date: 2021-08-12T15:10:05+02:00
New Revision: 62139c5b2563f99226d62da56dc205038cc2c819

URL: https://github.com/llvm/llvm-project/commit/62139c5b2563f99226d62da56dc205038cc2c819
DIFF: https://github.com/llvm/llvm-project/commit/62139c5b2563f99226d62da56dc205038cc2c819.diff

LOG: tsan: remove implicit memcpy in MutexSet::Desc::operator=()

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/tsan/rtl/tsan_mutexset.cpp b/compiler-rt/lib/tsan/rtl/tsan_mutexset.cpp
index d76febff2764..efc0e4195a12 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_mutexset.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_mutexset.cpp
@@ -14,10 +14,7 @@
 
 namespace __tsan {
 
-const uptr MutexSet::kMaxSize;
-
 MutexSet::MutexSet() {
-  internal_memset(&descs_, 0, sizeof(descs_));
 }
 
 void MutexSet::Add(u64 id, bool write, u64 epoch) {

diff  --git a/compiler-rt/lib/tsan/rtl/tsan_mutexset.h b/compiler-rt/lib/tsan/rtl/tsan_mutexset.h
index 606106f71145..a448cee5a877 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_mutexset.h
+++ b/compiler-rt/lib/tsan/rtl/tsan_mutexset.h
@@ -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;


        


More information about the llvm-commits mailing list