Skip to content

Commit e3e9425

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 3de7694 commit e3e9425

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ 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* dummy_data_block = new OverAligned[3];
52+
OverAligned* x = DoNotOptimize(dummy_data_block);
5253
assert(static_cast<void*>(x) == DummyData);
5354
assert(new_called == 1);
5455

55-
delete[] x;
56+
delete[] dummy_data_block;
5657
assert(delete_called == 1);
5758
}
5859

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ int main(int, char**) {
4848
// Test with an overaligned type
4949
{
5050
new_called = delete_called = 0;
51-
OverAligned* x = new OverAligned;
51+
OverAligned* dummy_data_block = new OverAligned;
52+
OverAligned* x = DoNotOptimize(dummy_data_block);
5253
assert(static_cast<void*>(x) == DummyData);
5354
assert(new_called == 1);
5455

55-
delete x;
56+
delete dummy_data_block;
5657
assert(delete_called == 1);
5758
}
5859

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ 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* dummy_data_block = new (std::nothrow) OverAligned;
51+
OverAligned* x = DoNotOptimize(dummy_data_block);
5152
assert(static_cast<void*>(x) == DummyData);
5253
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(new_nothrow_called == 1);
5354

54-
delete x;
55+
delete dummy_data_block;
5556
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(delete_called == 1);
5657
}
5758

0 commit comments

Comments
 (0)