[libcxx] r305955 - Attempt to avoid static init ordering issues with globalMemCounter
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 21 14:42:51 PDT 2017
Author: ericwf
Date: Wed Jun 21 16:42:50 2017
New Revision: 305955
URL: http://llvm.org/viewvc/llvm-project?rev=305955&view=rev
Log:
Attempt to avoid static init ordering issues with globalMemCounter
Modified:
libcxx/trunk/test/support/count_new.hpp
Modified: libcxx/trunk/test/support/count_new.hpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/count_new.hpp?rev=305955&r1=305954&r2=305955&view=diff
==============================================================================
--- libcxx/trunk/test/support/count_new.hpp (original)
+++ libcxx/trunk/test/support/count_new.hpp Wed Jun 21 16:42:50 2017
@@ -231,12 +231,17 @@ public:
const bool MemCounter::disable_checking = false;
#endif
-MemCounter globalMemCounter((MemCounter::MemCounterCtorArg_()));
+inline MemCounter* getGlobalMemCounter() {
+ static MemCounter counter((MemCounter::MemCounterCtorArg_()));
+ return &counter;
+}
+
+MemCounter &globalMemCounter = *getGlobalMemCounter();
#ifndef DISABLE_NEW_COUNT
void* operator new(std::size_t s) TEST_THROW_SPEC(std::bad_alloc)
{
- globalMemCounter.newCalled(s);
+ getGlobalMemCounter()->newCalled(s);
void* ret = std::malloc(s);
if (ret == nullptr)
detail::throw_bad_alloc_helper();
@@ -245,21 +250,21 @@ void* operator new(std::size_t s) TEST_T
void operator delete(void* p) TEST_NOEXCEPT
{
- globalMemCounter.deleteCalled(p);
+ getGlobalMemCounter()->deleteCalled(p);
std::free(p);
}
void* operator new[](std::size_t s) TEST_THROW_SPEC(std::bad_alloc)
{
- globalMemCounter.newArrayCalled(s);
+ getGlobalMemCounter()->newArrayCalled(s);
return operator new(s);
}
void operator delete[](void* p) TEST_NOEXCEPT
{
- globalMemCounter.deleteArrayCalled(p);
+ getGlobalMemCounter()->deleteArrayCalled(p);
operator delete(p);
}
More information about the cfe-commits
mailing list