Skip to content
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
11 changes: 9 additions & 2 deletions libcxx/test/benchmarks/allocation.bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
//
//===----------------------------------------------------------------------===//

// REQUIRES: -fsized-deallocation
// ADDITIONAL_COMPILE_FLAGS: -fsized-deallocation
// 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

#include "benchmark/benchmark.h"

Expand Down

This file was deleted.

10 changes: 8 additions & 2 deletions libcxx/test/libcxx/memory/shared_ptr_array.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
//

// UNSUPPORTED: c++03, c++11, c++14, c++17
// REQUIRES: -fsized-deallocation
// ADDITIONAL_COMPILE_FLAGS: -fsized-deallocation

// 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

// This test will fail with ASan if the implementation passes different sizes
// to corresponding allocation and deallocation functions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,50 @@
// XFAIL: target={{.+}}-zos{{.*}}

#include <new>
#include <cassert>
#include <cstddef>
#include <string>
#include <type_traits>
#include <typeinfo>

#include "test_macros.h"

int main(int, char**) {
constexpr bool test() {
static_assert(std::is_enum<std::align_val_t>::value, "");
static_assert(std::is_same<std::underlying_type<std::align_val_t>::type, std::size_t>::value, "");
static_assert(!std::is_constructible<std::align_val_t, std::size_t>::value, "");
static_assert(!std::is_constructible<std::size_t, std::align_val_t>::value, "");

{
static_assert(std::is_enum<std::align_val_t>::value, "");
static_assert(std::is_same<std::underlying_type<std::align_val_t>::type, std::size_t>::value, "");
static_assert(!std::is_constructible<std::align_val_t, std::size_t>::value, "");
static_assert(!std::is_constructible<std::size_t, std::align_val_t>::value, "");
auto a = std::align_val_t(0);
auto b = std::align_val_t(32);
auto c = std::align_val_t(-1);
assert(a != b);
assert(a == std::align_val_t(0));
assert(b == std::align_val_t(32));
assert(static_cast<std::size_t>(c) == static_cast<std::size_t>(-1));
}

return true;
}

int main(int, char**) {
test();
static_assert(test(), "");

#if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_RTTI)
{
constexpr auto a = std::align_val_t(0);
constexpr auto b = std::align_val_t(32);
constexpr auto c = std::align_val_t(-1);
static_assert(a != b, "");
static_assert(a == std::align_val_t(0), "");
static_assert(b == std::align_val_t(32), "");
static_assert(static_cast<std::size_t>(c) == (std::size_t)-1, "");
// Check that libc++ doesn't define align_val_t in a versioning namespace.
// And that it mangles the same in C++03 through C++17
# ifdef _MSC_VER
// MSVC uses a different C++ ABI with a different name mangling scheme.
// The type id name doesn't seem to contain the mangled form at all.
assert(typeid(std::align_val_t).name() == std::string("enum std::align_val_t"));
# else
assert(typeid(std::align_val_t).name() == std::string("St11align_val_t"));
# endif
}
#endif

return 0;
}
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));
test_with_interesting_alignments([](std::size_t size, std::size_t alignment) {
void* x = operator new[](size, static_cast<std::align_val_t>(alignment));
assert(x != nullptr);
assert(reinterpret_cast<std::uintptr_t>(x) % 64 == 0);
operator delete[](x, static_cast<std::align_val_t>(64));
}
assert(reinterpret_cast<std::uintptr_t>(x) % alignment == 0);
operator delete[](x, static_cast<std::align_val_t>(alignment));
});

// Test that the new handler is called if allocation fails
{
Expand Down
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 @@ -6,15 +6,29 @@
//
//===----------------------------------------------------------------------===//

// test sized operator delete[] replacement.
// Test sized operator delete[] replacement.

// Note that sized delete operator definitions below are simply ignored
// when sized deallocation is not supported, e.g., prior to C++14.
// 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

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

// 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
Expand Down Expand Up @@ -76,5 +90,5 @@ int main(int, char**)
assert(0 == unsized_delete_nothrow_called);
assert(1 == sized_delete_called);

return 0;
return 0;
}

This file was deleted.

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));
test_with_interesting_alignments([](std::size_t size, std::size_t alignment) {
void* x = operator new(size, static_cast<std::align_val_t>(alignment));
assert(x != nullptr);
assert(reinterpret_cast<std::uintptr_t>(x) % 64 == 0);
operator delete(x, static_cast<std::align_val_t>(64));
}
assert(reinterpret_cast<std::uintptr_t>(x) % alignment == 0);
operator delete(x, static_cast<std::align_val_t>(alignment));
});

// Test that the new handler is called if allocation fails
{
Expand Down
Loading
Loading