Skip to content

[libcxx] Improve libcxx tests when using Optimizations. #88897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ int main(int, char**) {
// Test with an overaligned type
{
new_called = delete_called = 0;
OverAligned* x = DoNotOptimize(new OverAligned[3]);
OverAligned* dummy_data_block = new OverAligned[3];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really still see the bug if you change all of those back to OverAligned* x = DoNotOptimize(new ...)?

It seems to me that the only necessary part of this patch is adding the missing DoNotOptimize calls in libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size_align_nothrow.replace.pass.cpp, libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size_align.replace.pass.cpp and libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size_align.replace.pass.cpp.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we do - hence the change in these tests to a different variant of the DoNotOptimize function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then let's delete dummy_data_block instead of x below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

OverAligned* x = DoNotOptimize(dummy_data_block);
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(static_cast<void*>(x) == DummyData);
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(new_called == 1);

delete[] x;
delete[] dummy_data_block;
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(delete_called == 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ int main(int, char**) {
// Test with an overaligned type
{
new_called = delete_called = 0;
OverAligned* x = new OverAligned[3];
OverAligned* dummy_data_block = new OverAligned[3];
OverAligned* x = DoNotOptimize(dummy_data_block);
assert(static_cast<void*>(x) == DummyData);
assert(new_called == 1);

delete[] x;
delete[] dummy_data_block;
assert(delete_called == 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ int main(int, char**) {
// Test with an overaligned type
{
new_called = delete_called = 0;
OverAligned* x = DoNotOptimize(new (std::nothrow) OverAligned[3]);
OverAligned* dummy_data_block = new (std::nothrow) OverAligned[3];
OverAligned* x = DoNotOptimize(dummy_data_block);
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(static_cast<void*>(x) == DummyData);
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(new_called == 1);

delete[] x;
delete[] dummy_data_block;
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(delete_called == 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ int main(int, char**) {
// Test with an overaligned type
{
new_called = delete_called = 0;
OverAligned* x = new OverAligned;
OverAligned* dummy_data_block = new OverAligned;
OverAligned* x = DoNotOptimize(dummy_data_block);
assert(static_cast<void*>(x) == DummyData);
assert(new_called == 1);

delete x;
delete dummy_data_block;
assert(delete_called == 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ int main(int, char**) {
// Test with an overaligned type
{
new_called = delete_called = 0;
OverAligned* x = DoNotOptimize(new (std::nothrow) OverAligned);
OverAligned* dummy_data_block = new (std::nothrow) OverAligned;
OverAligned* x = DoNotOptimize(dummy_data_block);
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(static_cast<void*>(x) == DummyData);
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(new_called == 1);

delete x;
delete dummy_data_block;
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(delete_called == 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ int main(int, char**) {
// Test with an overaligned type
{
new_nothrow_called = delete_called = 0;
OverAligned* x = new (std::nothrow) OverAligned;
OverAligned* dummy_data_block = new (std::nothrow) OverAligned;
OverAligned* x = DoNotOptimize(dummy_data_block);
assert(static_cast<void*>(x) == DummyData);
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(new_nothrow_called == 1);

delete x;
delete dummy_data_block;
ASSERT_WITH_OPERATOR_NEW_FALLBACKS(delete_called == 1);
}

Expand Down