Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ void my_new_handler() {
}

int main(int, char**) {
// Test that we can call the function directly
{
void* x = operator new(10, static_cast<std::align_val_t>(64), std::nothrow);
test_with_interesting_alignments([](std::size_t size, std::size_t alignment) {
void* x = operator new(size, static_cast<std::align_val_t>(alignment), std::nothrow);
assert(x != nullptr);
assert(reinterpret_cast<std::uintptr_t>(x) % 64 == 0);
operator delete(x, static_cast<std::align_val_t>(64), std::nothrow);
}
assert(reinterpret_cast<std::uintptr_t>(x) % alignment == 0);
operator delete(x, static_cast<std::align_val_t>(alignment), std::nothrow);
});

// Test that the new handler is called and we return nullptr if allocation fails
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,35 @@

// Test sized operator delete replacement.

// These compiler versions do not enable sized deallocation by default.
// UNSUPPORTED: clang-17, clang-18
// UNSUPPORTED: c++03, c++11

// These compiler versions and platforms don't enable sized deallocation by default.
// ADDITIONAL_COMPILE_FLAGS(clang-17): -fsized-deallocation
// ADDITIONAL_COMPILE_FLAGS(clang-18): -fsized-deallocation
// ADDITIONAL_COMPILE_FLAGS(apple-clang-15): -fsized-deallocation
// ADDITIONAL_COMPILE_FLAGS(apple-clang-16): -fsized-deallocation
// ADDITIONAL_COMPILE_FLAGS(target=x86_64-w64-windows-gnu): -fsized-deallocation
// ADDITIONAL_COMPILE_FLAGS(target=i686-w64-windows-gnu): -fsized-deallocation

// Android clang-r536225 identifies as clang-19.0 but it predates the real
// LLVM 19.0.0, so it also leaves sized deallocation off by default.
// UNSUPPORTED: android && clang-19.0

// UNSUPPORTED: sanitizer-new-delete, c++03, c++11
// XFAIL: apple-clang
// UNSUPPORTED: sanitizer-new-delete

// Sized deallocation was introduced in LLVM 11
// XFAIL: using-built-library-before-llvm-11

// AIX, z/OS, and MinGW default to -fno-sized-deallocation.
// XFAIL: target={{.+}}-aix{{.*}}, target={{.+}}-zos{{.*}}, target={{.+}}-windows-gnu
// AIX, and z/OS default to -fno-sized-deallocation.
// XFAIL: target={{.+}}-aix{{.*}}, target={{.+}}-zos{{.*}}

#if !defined(__cpp_sized_deallocation)
# error __cpp_sized_deallocation should be defined
#endif

#if !(__cpp_sized_deallocation >= 201309L)
# error expected __cpp_sized_deallocation >= 201309L
#endif

#include <new>
#include <cstddef>
Expand Down Expand Up @@ -65,5 +81,5 @@ int main(int, char**)
assert(1 == sized_delete_called);
assert(0 == unsized_delete_nothrow_called);

return 0;
return 0;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,35 @@ struct alignas(std::max_align_t) MaxAligned {
};
#endif // TEST_STD_VER >= 17

template <class F>
void test_with_interesting_alignments(F f) {
// First, check the basic case, a large allocation with alignment == size.
f(/* size */ 64, /* alignment */ 64);

// Size being a multiple of alignment also needs to be supported.
f(/* size */ 64, /* alignment */ 32);

// Test with a non power-of-two size.
f(/* size */ 10, /* alignment */ 64);

// When aligned allocation is implemented using aligned_alloc,
// that function requires a minimum alignment of sizeof(void*).
//
// Check that we can also create overaligned allocations with
// an alignment argument less than sizeof(void*).
f(/* size */ 2, /* alignment */ 2);

// When implemented using the C11 aligned_alloc() function,
// that requires that size be a multiple of alignment.
// However, the C++ operator new has no such requirements.
//
// Check that we can create an overaligned allocation that does
// adhere to not have this constraint.
f(/* size */ 1, /* alignment */ 128);

// Finally, test size > alignment, but with size not being
// a multiple of alignment.
f(/* size */ 65, /* alignment */ 32);
}

#endif // TEST_STD_LANGUAGE_SUPPORT_SUPPORT_DYNAMIC_NEW_DELETE_TYPES_H
8 changes: 0 additions & 8 deletions libcxx/utils/libcxx/test/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,6 @@ def _mingwSupportsModules(cfg):
when=lambda cfg: hasCompileFlag(cfg, "-fconstexpr-ops-limit=1"),
),
Feature(name="has-fblocks", when=lambda cfg: hasCompileFlag(cfg, "-fblocks")),
Feature(
name="-fsized-deallocation",
when=lambda cfg: hasCompileFlag(cfg, "-fsized-deallocation"),
),
Feature(
name="-faligned-allocation",
when=lambda cfg: hasCompileFlag(cfg, "-faligned-allocation"),
),
Feature(
name="fdelayed-template-parsing",
when=lambda cfg: hasCompileFlag(cfg, "-fdelayed-template-parsing"),
Expand Down