From 107d6d684539a034c6ab3a1ae915179c5bbde8ba Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Thu, 22 Mar 2018 21:28:09 +0000 Subject: Use DoNotOptimize to prevent new/delete elision. The new/delete tests, in particular those which test replacement functions, often fail when the optimizer is enabled because the calls to new/delete may be optimized away, regardless of their side-effects. This patch converts the tests to use DoNotOptimize in order to prevent the elision. llvm-svn: 328245 --- .../memory/default.allocator/allocator.members/allocate.pass.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'libcxx/test/std/utilities') diff --git a/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp index 930da0b79b8..70c5e46965a 100644 --- a/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp +++ b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp @@ -14,6 +14,7 @@ #include #include +#include #include "test_macros.h" #include "count_new.hpp" @@ -59,7 +60,8 @@ void test_aligned() { assert(T::constructed == 0); globalMemCounter.last_new_size = 0; globalMemCounter.last_new_align = 0; - T* volatile ap = a.allocate(3); + T* ap = a.allocate(3); + DoNotOptimize(ap); assert(globalMemCounter.checkOutstandingNewEq(1)); assert(globalMemCounter.checkNewCalledEq(1)); assert(globalMemCounter.checkAlignedNewCalledEq(ExpectAligned)); @@ -79,6 +81,7 @@ void test_aligned() { globalMemCounter.last_new_size = 0; globalMemCounter.last_new_align = 0; T* volatile ap2 = a.allocate(11, (const void*)5); + DoNotOptimize(ap2); assert(globalMemCounter.checkOutstandingNewEq(1)); assert(globalMemCounter.checkNewCalledEq(1)); assert(globalMemCounter.checkAlignedNewCalledEq(ExpectAligned)); @@ -87,6 +90,7 @@ void test_aligned() { assert(T::constructed == 0); globalMemCounter.last_delete_align = 0; a.deallocate(ap2, 11); + DoNotOptimize(ap2); assert(globalMemCounter.checkOutstandingNewEq(0)); assert(globalMemCounter.checkDeleteCalledEq(1)); assert(globalMemCounter.checkAlignedDeleteCalledEq(ExpectAligned)); -- cgit v1.2.3