Skip to content

Commit 48a1b8e

Browse files
committed
[libcxx] Add DoNotOptimize function call to libcxx tests where appropriate
It has been seen, at high levels of optimizations, issues with comparing the pointer values in some libcxx tests attaining to the assert comparing the pointer of a global variable to that of one created locally within the test. These tests follow the same logic as others that utilize the `DoNotOptimize` function, however these tests do not. To ensure the correct behaviour at high levels of optimization, these tests now utilize the function when building the tests. This allows for the correct behaviour to be observed when running the tests.
1 parent 3f94851 commit 48a1b8e

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size_align.replace.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ int main(int, char**) {
4848
// Test with an overaligned type
4949
{
5050
new_called = delete_called = 0;
51-
OverAligned* x = new OverAligned[3];
51+
OverAligned* x = DoNotOptimize(new OverAligned[3]);
5252
assert(static_cast<void*>(x) == DummyData);
5353
assert(new_called == 1);
5454

libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size_align.replace.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ int main(int, char**) {
4848
// Test with an overaligned type
4949
{
5050
new_called = delete_called = 0;
51-
OverAligned* x = new OverAligned;
51+
OverAligned* x = DoNotOptimize(new OverAligned);
5252
assert(static_cast<void*>(x) == DummyData);
5353
assert(new_called == 1);
5454

libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size_align_nothrow.replace.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int main(int, char**) {
4747
// Test with an overaligned type
4848
{
4949
new_nothrow_called = delete_called = 0;
50-
OverAligned* x = new (std::nothrow) OverAligned;
50+
OverAligned* x = DoNotOptimize(new (std::nothrow) OverAligned);
5151
assert(static_cast<void*>(x) == DummyData);
5252
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(new_nothrow_called == 1);
5353

0 commit comments

Comments
 (0)