Skip to content

Commit 3de7694

Browse files
committed
[libcxx] Update DoNotOptimize to utilize L Value Reference Variant.
As part of the libcxx tests, there is a function provided called `DoNotOptimize`. The tests currently utilise a version which only uses the value as an input, leading to the compiler not removing information relating to the data-flow for the value. This leads to issues when comparing the pointer values, where one is a global pointer and the other a pointer which is local to the function being executed. Another version of `DoNotOptimize` is available which allows for the value to be an input and output of the inline assembly, which allows for the pointers to be successfully compared to one another. This function however only accepts an L Value reference, where the values are initialized as R value reference, so use the variant of `DoNotOptmize` described in the first paragraph. To enable the use of the second variant in the tests, the type of reference has been updated within the test to be an L Value reference, to correctly utlize the correct variant of `DoNotOptimize` that allows for successful comparison of the pointers.
1 parent 20d653f commit 3de7694

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.indirect.pass.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ int main(int, char**) {
5151
// Test with an overaligned type
5252
{
5353
new_called = delete_called = 0;
54-
OverAligned* x = DoNotOptimize(new OverAligned[3]);
54+
OverAligned* dummy_data_block = new OverAligned[3];
55+
OverAligned* x = DoNotOptimize(dummy_data_block);
5556
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(static_cast<void*>(x) == DummyData);
5657
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(new_called == 1);
5758

58-
delete[] x;
59+
delete[] dummy_data_block;
5960
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(delete_called == 1);
6061
}
6162

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ int main(int, char**) {
5555
// Test with an overaligned type
5656
{
5757
new_called = delete_called = 0;
58-
OverAligned* x = DoNotOptimize(new (std::nothrow) OverAligned[3]);
58+
OverAligned* dummy_data_block = new (std::nothrow) OverAligned[3];
59+
OverAligned* x = DoNotOptimize(dummy_data_block);
5960
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(static_cast<void*>(x) == DummyData);
6061
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(new_called == 1);
6162

62-
delete[] x;
63+
delete[] dummy_data_block;
6364
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(delete_called == 1);
6465
}
6566

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ int main(int, char**) {
5454
// Test with an overaligned type
5555
{
5656
new_called = delete_called = 0;
57-
OverAligned* x = DoNotOptimize(new (std::nothrow) OverAligned);
57+
OverAligned* dummy_data_block = new (std::nothrow) OverAligned;
58+
OverAligned* x = DoNotOptimize(dummy_data_block);
5859
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(static_cast<void*>(x) == DummyData);
5960
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(new_called == 1);
6061

61-
delete x;
62+
delete dummy_data_block;
6263
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(delete_called == 1);
6364
}
6465

0 commit comments

Comments
 (0)