summaryrefslogtreecommitdiffstats
path: root/libcxx/test/support
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2017-06-21 21:42:50 +0000
committerEric Fiselier <eric@efcs.ca>2017-06-21 21:42:50 +0000
commit05092380773149492ca28d7af23869a18983a223 (patch)
treeb3515dcde6caae3e092f2e8232c83a9e0a770881 /libcxx/test/support
parentbac3570d534bd600de05f9d3847abf96cac220c2 (diff)
downloadbcm5719-llvm-05092380773149492ca28d7af23869a18983a223.tar.gz
bcm5719-llvm-05092380773149492ca28d7af23869a18983a223.zip
Attempt to avoid static init ordering issues with globalMemCounter
llvm-svn: 305955
Diffstat (limited to 'libcxx/test/support')
-rw-r--r--libcxx/test/support/count_new.hpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/libcxx/test/support/count_new.hpp b/libcxx/test/support/count_new.hpp
index 1b05fe35e94..c001c0340fa 100644
--- a/libcxx/test/support/count_new.hpp
+++ b/libcxx/test/support/count_new.hpp
@@ -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_THROW_SPEC(std::bad_alloc)
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);
}
OpenPOWER on IntegriCloud