From 62139c5b2563f99226d62da56dc205038cc2c819 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 12 Aug 2021 14:47:47 +0200 Subject: [PATCH] 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 --- compiler-rt/lib/tsan/rtl/tsan_mutexset.cpp | 3 --- compiler-rt/lib/tsan/rtl/tsan_mutexset.h | 14 ++++++++------ 2 files changed, 8 insertions(+), 9 deletions(-) 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;