[compiler-rt] 4ab7665 - tsan: Support constructor arguments via New

Marco Elver via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 30 03:51:03 PDT 2021


Author: Marco Elver
Date: 2021-07-30T12:49:08+02:00
New Revision: 4ab76659198463eb838a0dcef696704186fe036c

URL: https://github.com/llvm/llvm-project/commit/4ab76659198463eb838a0dcef696704186fe036c
DIFF: https://github.com/llvm/llvm-project/commit/4ab76659198463eb838a0dcef696704186fe036c.diff

LOG: tsan: Support constructor arguments via New

Make New<>() a variadic function template and forward any arguments to
the constructor. std::forward<>() is inlined to avoid including
<utility>.

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/tsan/rtl/tsan_mman.h b/compiler-rt/lib/tsan/rtl/tsan_mman.h
index 089898a6c757..efea5e5abdec 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_mman.h
+++ b/compiler-rt/lib/tsan/rtl/tsan_mman.h
@@ -51,9 +51,9 @@ void invoke_free_hook(void *ptr);
 void *Alloc(uptr sz);
 void FreeImpl(void *p);
 
-template <typename T>
-T *New() {
-  return new (Alloc(sizeof(T))) T();
+template <typename T, typename... Args>
+T *New(Args &&...args) {
+  return new (Alloc(sizeof(T))) T(static_cast<Args &&>(args)...);
 }
 
 template <typename T>

diff  --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp b/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
index 70573a644784..15fa368b9891 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
@@ -101,7 +101,7 @@ static ThreadContextBase *CreateThreadContext(u32 tid) {
       CHECK("unable to mprotect" && 0);
     }
   }
-  return new (Alloc(sizeof(ThreadContext))) ThreadContext(tid);
+  return New<ThreadContext>(tid);
 }
 
 #if !SANITIZER_GO


        


More information about the llvm-commits mailing list