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
This commit is contained in:
Marco Elver 2021-07-30 12:22:07 +02:00
parent 98b5659b53
commit 4ab7665919
2 changed files with 4 additions and 4 deletions

View File

@ -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>

View File

@ -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