[libcxx] [test] Fix mismatches between aligned operator new and std::free

The XFAIL comments about VCRuntime not providing aligned operator new
are outdated; these days VCRuntime does provide them.

However, the tests used to fail on Windows, as the pointers allocated
with an aligned operator new (which is implemented with _aligned_malloc
on Windows) can't be freed using std::free() on Windows (but they need
to be freed with the corresponding function _aligned_free instead).

Instead override the aligned operator new to return a dummy suitably
aligned pointer instead, like other tests that override aligned operator
new.

Also override `operator delete[]` instead of plain `operator delete`
in the array testcase; the fallback from `operator delete[]` to
user defined `operator delete` doesn't work in all DLL build
configurations on Windows.

Also expand the TEST_NOEXCEPT macros, as these tests only are built
in C++17 mode.

By providing the aligned operator new within the tests, this also makes
these test cases pass when testing back deployment on macOS 10.9.

Differential Revision: https://reviews.llvm.org/D105962
This commit is contained in:
Martin Storsjö 2021-07-13 12:49:19 +00:00
parent c97cb11efd
commit 6596778b46
2 changed files with 22 additions and 20 deletions

View File

@ -18,12 +18,6 @@
// However, support for that was broken prior to Clang 8 and AppleClang 11.
// UNSUPPORTED: apple-clang-9, apple-clang-10
// UNSUPPORTED: clang-5, clang-6, clang-7
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12|13}}
// On Windows libc++ doesn't provide its own definitions for new/delete
// but instead depends on the ones in VCRuntime. However VCRuntime does not
// yet provide aligned new/delete definitions so this test fails to compile/link.
// XFAIL: LIBCXX-WINDOWS-FIXME
// Libcxx when built for z/OS doesn't contain the aligned allocation functions,
// nor does the dynamic library shipped with z/OS.
@ -48,22 +42,29 @@ void reset() {
aligned_delete_called = 0;
}
void operator delete(void* p) TEST_NOEXCEPT
alignas(OverAligned) char DummyData[OverAligned * 4];
void* operator new [] (std::size_t s, std::align_val_t)
{
assert(s <= sizeof(DummyData));
return DummyData;
}
void operator delete [] (void* p) noexcept
{
++unsized_delete_called;
std::free(p);
}
void operator delete(void* p, const std::nothrow_t&) TEST_NOEXCEPT
void operator delete [] (void* p, const std::nothrow_t&) noexcept
{
++unsized_delete_nothrow_called;
std::free(p);
}
void operator delete [] (void* p, std::align_val_t) TEST_NOEXCEPT
void operator delete [] (void*, std::align_val_t) noexcept
{
++aligned_delete_called;
std::free(p);
}
struct alignas(OverAligned) A {};

View File

@ -18,12 +18,6 @@
// However, support for that was broken prior to Clang 8 and AppleClang 11.
// UNSUPPORTED: apple-clang-9, apple-clang-10
// UNSUPPORTED: clang-5, clang-6, clang-7
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12|13}}
// On Windows libc++ doesn't provide its own definitions for new/delete
// but instead depends on the ones in VCRuntime. However VCRuntime does not
// yet provide aligned new/delete definitions so this test fails to compile/link.
// XFAIL: LIBCXX-WINDOWS-FIXME
// Libcxx when built for z/OS doesn't contain the aligned allocation functions,
// nor does the dynamic library shipped with z/OS.
@ -48,22 +42,29 @@ void reset() {
aligned_delete_called = 0;
}
void operator delete(void* p) TEST_NOEXCEPT
alignas(OverAligned) char DummyData[OverAligned * 4];
void* operator new (std::size_t s, std::align_val_t)
{
assert(s <= sizeof(DummyData));
return DummyData;
}
void operator delete(void* p) noexcept
{
++unsized_delete_called;
std::free(p);
}
void operator delete(void* p, const std::nothrow_t&) TEST_NOEXCEPT
void operator delete(void* p, const std::nothrow_t&) noexcept
{
++unsized_delete_nothrow_called;
std::free(p);
}
void operator delete(void* p, std::align_val_t) TEST_NOEXCEPT
void operator delete(void*, std::align_val_t) noexcept
{
++aligned_delete_called;
std::free(p);
}
struct alignas(OverAligned) A {};