[libcxx-commits] [libcxx] edad54e - Reapply "[libc++] Remove __libcpp_allocate" (#222814) (#229771)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Oct 21 06:46:01 PDT 2026


Author: Nikolas Klauser
Date: 2026-10-21T15:45:56+02:00
New Revision: edad54e08d3b5f8e8669e7caffcfd406c8bdf5c0

URL: https://github.com/llvm/llvm-project/commit/edad54e08d3b5f8e8669e7caffcfd406c8bdf5c0
DIFF: https://github.com/llvm/llvm-project/commit/edad54e08d3b5f8e8669e7caffcfd406c8bdf5c0.diff

LOG: Reapply "[libc++] Remove __libcpp_allocate" (#222814) (#229771)

The crash in Clang that caused the revert has been fixed. This works
around the issue for old compilers by not using `__builtin_operator_{new,delete}` during constant evaluation.

Original commit message:

We use `__libcpp_allocate` and friends only in very specific
circumstances.
Instead of providing a private API we can make `std::allocator` the
default
API for the uses of `__libcpp_allocate`.

This reverts commit f896082fb9ea598c548bcb63515da7b23ff40f6d.

Added: 
    

Modified: 
    libcxx/include/CMakeLists.txt
    libcxx/include/__configuration/compiler.h
    libcxx/include/__memory/allocator.h
    libcxx/include/__memory/shared_ptr.h
    libcxx/include/__memory/unique_temporary_buffer.h
    libcxx/include/__utility/small_buffer.h
    libcxx/include/module.modulemap.in
    libcxx/include/new
    libcxx/src/include/aligned_alloc.h
    libcxx/test/std/containers/container.adaptors/flat.map/flat.map.capacity/max_size.pass.cpp
    libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.capacity/max_size.pass.cpp
    libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.capacity/max_size.pass.cpp
    libcxx/test/std/containers/container.adaptors/flat.set/flat.set.capacity/max_size.pass.cpp
    libcxx/test/std/language.support/support.dynamic/hardware_inference_size.compile.pass.cpp
    libcxx/test/std/numerics/numarray/template.valarray/valarray.cons/size.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/pointer_destruction.pass.cpp

Removed: 
    libcxx/include/__new/allocate.h
    libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp


################################################################################
diff  --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2219c69f99addc..fcb66d5fe2f48a 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -655,7 +655,6 @@ set(files
   __mutex/tag_types.h
   __mutex/unique_lock.h
   __new/align_val_t.h
-  __new/allocate.h
   __new/destroying_delete_t.h
   __new/exceptions.h
   __new/global_new_delete.h

diff  --git a/libcxx/include/__configuration/compiler.h b/libcxx/include/__configuration/compiler.h
index c4896347921a22..d4d8144ef159f2 100644
--- a/libcxx/include/__configuration/compiler.h
+++ b/libcxx/include/__configuration/compiler.h
@@ -71,6 +71,12 @@
 #    error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11"
 #  endif
 
+#  ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
+#    define _LIBCPP_DEFAULT_NEW_ALIGNMENT __STDCPP_DEFAULT_NEW_ALIGNMENT__
+#  else
+#    define _LIBCPP_DEFAULT_NEW_ALIGNMENT __BIGGEST_ALIGNMENT__
+#  endif
+
 #endif
 
 #endif // _LIBCPP___CONFIGURATION_COMPILER_H

diff  --git a/libcxx/include/__memory/allocator.h b/libcxx/include/__memory/allocator.h
index dd8c8647c178a2..aaa9da5a87ce12 100644
--- a/libcxx/include/__memory/allocator.h
+++ b/libcxx/include/__memory/allocator.h
@@ -15,7 +15,7 @@
 #include <__cstddef/size_t.h>
 #include <__memory/addressof.h>
 #include <__memory/allocator_traits.h>
-#include <__new/allocate.h>
+#include <__new/align_val_t.h>
 #include <__new/exceptions.h>
 #include <__type_traits/is_const.h>
 #include <__type_traits/is_constant_evaluated.h>
@@ -58,6 +58,19 @@ struct __non_trivially_default_constructible_if<true, _Unique> {
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __non_trivially_default_constructible_if() {}
 };
 
+// TODO(LLVM 26): Remove these wrappers and call them unconditionally in `allocator::allocate` and
+// `allocator::deallocate`. These are here to the `__builtin_operator`s are never in a constant
+// context due to a Clang bug.
+template <class _Tp, class... _Args>
+_Tp* __operator_new_wrapper(size_t __count, _Args&&... __args) {
+  return static_cast<_Tp*>(__builtin_operator_new(__count * sizeof(_Tp), std::forward<_Args>(__args)...));
+}
+
+template <class... _Args>
+void __operator_delete_wrapper(_Args&&... __args) {
+  return __builtin_operator_delete(std::forward<_Args>(__args)...);
+}
+
 template <class _Tp>
 class allocator
 // TODO(LLVM 25): Remove the opt-out
@@ -86,11 +99,13 @@ class allocator
     static_assert(sizeof(_Tp) >= 0, "cannot allocate memory for an incomplete type");
     if (__n > allocator_traits<allocator>::max_size(*this))
       std::__throw_bad_array_new_length();
-    if (__libcpp_is_constant_evaluated()) {
-      return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
-    } else {
-      return std::__libcpp_allocate<_Tp>(__element_count(__n));
-    }
+    if (__libcpp_is_constant_evaluated())
+      return static_cast<_Tp*>(::operator new(sizeof(_Tp) * __n));
+#if _LIBCPP_HAS_ALIGNED_ALLOCATION
+    if _LIBCPP_CONSTEXPR (_LIBCPP_ALIGNOF(value_type) > _LIBCPP_DEFAULT_NEW_ALIGNMENT)
+      return std::__operator_new_wrapper<value_type>(__n, static_cast<align_val_t>(_LIBCPP_ALIGNOF(value_type)));
+#endif
+    return std::__operator_new_wrapper<value_type>(__n);
   }
 
 #if _LIBCPP_STD_VER >= 23
@@ -100,14 +115,26 @@ class allocator
   }
 #endif
 
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void deallocate(_Tp* __p, size_t __n) _NOEXCEPT {
-    if (__libcpp_is_constant_evaluated()) {
-      ::operator delete(__p);
-    } else {
-      std::__libcpp_deallocate<_Tp>(__p, __element_count(__n));
-    }
+#if defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309L
+#  define _LIBCPP_ONLY_IF_SIZED_DEALLOCATION(...) __VA_ARGS__
+#else
+#  define _LIBCPP_ONLY_IF_SIZED_DEALLOCATION(...) /* nothing */
+#endif
+
+  _LIBCPP_HIDE_FROM_ABI
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 void deallocate(_Tp* __p, [[__maybe_unused__]] size_t __n) _NOEXCEPT {
+    if (__libcpp_is_constant_evaluated())
+      return ::operator delete(__p);
+#if _LIBCPP_HAS_ALIGNED_ALLOCATION
+    if (_LIBCPP_ALIGNOF(value_type) > _LIBCPP_DEFAULT_NEW_ALIGNMENT)
+      return std::__operator_delete_wrapper(__p _LIBCPP_ONLY_IF_SIZED_DEALLOCATION(, __n * sizeof(value_type)),
+                                            static_cast<align_val_t>(_LIBCPP_ALIGNOF(value_type)));
+#endif
+    return std::__operator_delete_wrapper(__p _LIBCPP_ONLY_IF_SIZED_DEALLOCATION(, __n * sizeof(value_type)));
   }
 
+#undef _LIBCPP_ONLY_IF_SIZED_DEALLOCATION
+
   // C++20 Removed members
 #if _LIBCPP_STD_VER <= 17
   _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp* pointer;

diff  --git a/libcxx/include/__memory/shared_ptr.h b/libcxx/include/__memory/shared_ptr.h
index fd3a7cdcddf3c0..0db58b37a6288b 100644
--- a/libcxx/include/__memory/shared_ptr.h
+++ b/libcxx/include/__memory/shared_ptr.h
@@ -52,6 +52,7 @@
 #include <__type_traits/remove_extent.h>
 #include <__type_traits/remove_pointer.h>
 #include <__type_traits/remove_reference.h>
+#include <__type_traits/type_identity.h>
 #include <__type_traits/void_t.h>
 #include <__utility/declval.h>
 #include <__utility/exception_guard.h>

diff  --git a/libcxx/include/__memory/unique_temporary_buffer.h b/libcxx/include/__memory/unique_temporary_buffer.h
index 32a3f0f081c00e..ec98fdea890023 100644
--- a/libcxx/include/__memory/unique_temporary_buffer.h
+++ b/libcxx/include/__memory/unique_temporary_buffer.h
@@ -16,7 +16,6 @@
 #include <__cstddef/ptr
diff _t.h>
 #include <__memory/allocator.h>
 #include <__memory/unique_ptr.h>
-#include <__new/allocate.h>
 #include <__new/global_new_delete.h>
 #include <__type_traits/is_constant_evaluated.h>
 
@@ -40,7 +39,11 @@ struct __temporary_buffer_deleter {
       return;
     }
 
-    std::__libcpp_deallocate_unsized<_Tp>(__ptr);
+#if _LIBCPP_HAS_ALIGNED_ALLOCATION
+    if _LIBCPP_CONSTEXPR (_LIBCPP_ALIGNOF(_Tp) > _LIBCPP_DEFAULT_NEW_ALIGNMENT)
+      return __builtin_operator_delete(__ptr, static_cast<align_val_t>(_LIBCPP_ALIGNOF(_Tp)));
+#endif
+    return __builtin_operator_delete(__ptr);
   }
 };
 
@@ -64,14 +67,14 @@ __allocate_unique_temporary_buffer(ptr
diff _t __count) {
     __count = __max_count;
   while (__count > 0) {
 #if _LIBCPP_HAS_ALIGNED_ALLOCATION
-    if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) {
+    if _LIBCPP_CONSTEXPR (_LIBCPP_ALIGNOF(_Tp) > _LIBCPP_DEFAULT_NEW_ALIGNMENT) {
       align_val_t __al = align_val_t(_LIBCPP_ALIGNOF(_Tp));
       __ptr            = static_cast<_Tp*>(::operator new(__count * sizeof(_Tp), __al, nothrow));
     } else {
       __ptr = static_cast<_Tp*>(::operator new(__count * sizeof(_Tp), nothrow));
     }
 #else
-    if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) {
+    if _LIBCPP_CONSTEXPR (_LIBCPP_ALIGNOF(_Tp) > _LIBCPP_DEFAULT_NEW_ALIGNMENT) {
       // Since aligned operator new is unavailable, constructs an empty buffer rather than one with invalid alignment.
       return __unique_buffer_type();
     }

diff  --git a/libcxx/include/__new/allocate.h b/libcxx/include/__new/allocate.h
deleted file mode 100644
index b9bc2e1a50710e..00000000000000
--- a/libcxx/include/__new/allocate.h
+++ /dev/null
@@ -1,78 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP___NEW_ALLOCATE_H
-#define _LIBCPP___NEW_ALLOCATE_H
-
-#include <__config>
-#include <__cstddef/max_align_t.h>
-#include <__cstddef/size_t.h>
-#include <__new/align_val_t.h>
-#include <__type_traits/type_identity.h>
-#include <__utility/element_count.h>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#  pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-_LIBCPP_CONSTEXPR inline _LIBCPP_HIDE_FROM_ABI bool __is_overaligned_for_new(size_t __align) _NOEXCEPT {
-#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
-  return __align > __STDCPP_DEFAULT_NEW_ALIGNMENT__;
-#else
-  return __align > _LIBCPP_ALIGNOF(max_align_t);
-#endif
-}
-
-template <class _Tp>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _Tp*
-__libcpp_allocate(__element_count __n, [[__maybe_unused__]] size_t __align = _LIBCPP_ALIGNOF(_Tp)) {
-  size_t __size = static_cast<size_t>(__n) * sizeof(_Tp);
-#if _LIBCPP_HAS_ALIGNED_ALLOCATION
-  if (__is_overaligned_for_new(__align))
-    return static_cast<_Tp*>(__builtin_operator_new(__size, static_cast<align_val_t>(__align)));
-#endif
-
-  return static_cast<_Tp*>(__builtin_operator_new(__size));
-}
-
-#if defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309L
-#  define _LIBCPP_ONLY_IF_SIZED_DEALLOCATION(...) __VA_ARGS__
-#else
-#  define _LIBCPP_ONLY_IF_SIZED_DEALLOCATION(...) /* nothing */
-#endif
-
-template <class _Tp>
-inline _LIBCPP_HIDE_FROM_ABI void
-__libcpp_deallocate(__type_identity_t<_Tp>* __ptr,
-                    __element_count __n,
-                    [[__maybe_unused__]] size_t __align = _LIBCPP_ALIGNOF(_Tp)) _NOEXCEPT {
-  [[__maybe_unused__]] size_t __size = static_cast<size_t>(__n) * sizeof(_Tp);
-#if _LIBCPP_HAS_ALIGNED_ALLOCATION
-  if (__is_overaligned_for_new(__align))
-    return __builtin_operator_delete(
-        __ptr _LIBCPP_ONLY_IF_SIZED_DEALLOCATION(, __size), static_cast<align_val_t>(__align));
-#endif
-  return __builtin_operator_delete(__ptr _LIBCPP_ONLY_IF_SIZED_DEALLOCATION(, __size));
-}
-
-#undef _LIBCPP_ONLY_IF_SIZED_DEALLOCATION
-
-template <class _Tp>
-inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate_unsized(
-    __type_identity_t<_Tp>* __ptr, [[__maybe_unused__]] size_t __align = _LIBCPP_ALIGNOF(_Tp)) _NOEXCEPT {
-#if _LIBCPP_HAS_ALIGNED_ALLOCATION
-  if (__is_overaligned_for_new(__align))
-    return __builtin_operator_delete(__ptr, static_cast<align_val_t>(__align));
-#endif
-  return __builtin_operator_delete(__ptr);
-}
-_LIBCPP_END_NAMESPACE_STD
-
-#endif // _LIBCPP___NEW_ALLOCATE_H

diff  --git a/libcxx/include/__utility/small_buffer.h b/libcxx/include/__utility/small_buffer.h
index 0dae0544cdecee..98577bbc0564c0 100644
--- a/libcxx/include/__utility/small_buffer.h
+++ b/libcxx/include/__utility/small_buffer.h
@@ -14,7 +14,6 @@
 #include <__cstddef/size_t.h>
 #include <__memory/allocator.h>
 #include <__memory/construct_at.h>
-#include <__new/allocate.h>
 #include <__new/launder.h>
 #include <__type_traits/decay.h>
 #include <__type_traits/is_trivially_constructible.h>

diff  --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index 76a9df3820e3e4..6ca65ba556fa1c 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -1787,11 +1787,6 @@ module std {
   module new {
     header "new"
     module align_val_t          { header "__new/align_val_t.h" }
-    module allocate {
-      header "__new/allocate.h"
-      export std.utility.element_count // used as part of the API
-      export * // TODO: Workaround for https://llvm.org/PR120108
-    }
     module destroying_delete_t  { header "__new/destroying_delete_t.h" }
     module exceptions           { header "__new/exceptions.h" }
     module global_new_delete    {

diff  --git a/libcxx/include/new b/libcxx/include/new
index 673e105bc5230b..7b7be39537edc7 100644
--- a/libcxx/include/new
+++ b/libcxx/include/new
@@ -91,7 +91,6 @@ void  operator delete[](void* ptr, void*) noexcept;                     // const
 #else
 #  include <__config>
 #  include <__new/align_val_t.h>
-#  include <__new/allocate.h>
 #  include <__new/exceptions.h>
 #  include <__new/global_new_delete.h>
 #  include <__new/new_handler.h>

diff  --git a/libcxx/src/include/aligned_alloc.h b/libcxx/src/include/aligned_alloc.h
index 1b24b579ebd15e..25a628f06b128a 100644
--- a/libcxx/src/include/aligned_alloc.h
+++ b/libcxx/src/include/aligned_alloc.h
@@ -23,7 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 // Low-level helpers to call the aligned allocation and deallocation functions
 // on the target platform. This is used to implement libc++'s own memory
 // allocation routines -- if you need to allocate memory inside the library,
-// chances are that you want to use `__libcpp_allocate` instead.
+// chances are that you want to use `allocator::allocate` instead.
 //
 // Returns the allocated memory, or `nullptr` on failure.
 inline _LIBCPP_HIDE_FROM_ABI void* __libcpp_aligned_alloc(std::size_t __alignment, std::size_t __size) {

diff  --git a/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp b/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
deleted file mode 100644
index 282d49d727c8c3..00000000000000
--- a/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
+++ /dev/null
@@ -1,252 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// Test libc++'s implementation of align_val_t, and the relevant new/delete
-// overloads in all dialects when -faligned-allocation is present.
-
-// Libc++ when built for z/OS doesn't contain the aligned allocation functions,
-// nor does the dynamic library shipped with z/OS.
-// XFAIL: target={{.+}}-zos{{.*}}
-
-// XFAIL: sanitizer-new-delete && !hwasan
-
-// TODO: Investigate this failure
-// UNSUPPORTED: ubsan
-
-// GCC doesn't support the aligned-allocation flags.
-// XFAIL: gcc
-
-// ADDITIONAL_COMPILE_FLAGS: -I %{libcxx-dir}/src -Wno-macro-redefined
-
-// RUN: %{build} -faligned-allocation -fsized-deallocation
-// RUN: %{run}
-// RUN: %{build} -faligned-allocation -fno-sized-deallocation -DNO_SIZE
-// RUN: %{run}
-// RUN: %{build} -fno-aligned-allocation -fsized-deallocation -DNO_ALIGN
-// RUN: %{run}
-// RUN: %{build} -fno-aligned-allocation -fno-sized-deallocation -DNO_ALIGN -DNO_SIZE
-// RUN: %{run}
-
-#include <cassert>
-#include <cstdlib>
-#include <new>
-
-#include "test_macros.h"
-
-#include "include/aligned_alloc.h"
-
-struct alloc_stats {
-  alloc_stats() { reset(); }
-
-  int aligned_sized_called;
-  int aligned_called;
-  int sized_called;
-  int plain_called;
-  int last_size;
-  int last_align;
-
-  void reset() {
-    aligned_sized_called = aligned_called = sized_called = plain_called = 0;
-    last_align = last_size = -1;
-  }
-
-  bool expect_plain() const {
-    assert(aligned_sized_called == 0);
-    assert(aligned_called == 0);
-    assert(sized_called == 0);
-    assert(last_size == -1);
-    assert(last_align == -1);
-    return plain_called == 1;
-  }
-
-  bool expect_size(int n) const {
-    assert(plain_called == 0);
-    assert(aligned_sized_called == 0);
-    assert(aligned_called == 0);
-    assert(last_size == n);
-    assert(last_align == -1);
-    return sized_called == 1;
-  }
-
-  bool expect_align(int a) const {
-    assert(plain_called == 0);
-    assert(aligned_sized_called == 0);
-    assert(sized_called == 0);
-    assert(last_size == -1);
-    assert(last_align == a);
-    return aligned_called == 1;
-  }
-
-  bool expect_size_align(int n, int a) const {
-    assert(plain_called == 0);
-    assert(sized_called == 0);
-    assert(aligned_called == 0);
-    assert(last_size == n);
-    assert(last_align == a);
-    return aligned_sized_called == 1;
-  }
-};
-alloc_stats stats;
-
-void operator delete(void* p) TEST_NOEXCEPT {
-  ::free(p);
-  stats.plain_called++;
-  stats.last_size = stats.last_align = -1;
-}
-
-#ifndef NO_SIZE
-void operator delete(void* p, std::size_t n) TEST_NOEXCEPT {
-  ::free(p);
-  stats.sized_called++;
-  stats.last_size  = n;
-  stats.last_align = -1;
-}
-#endif
-
-#ifndef NO_ALIGN
-void operator delete(void* p, std::align_val_t a) TEST_NOEXCEPT {
-  std::__libcpp_aligned_free(p);
-  stats.aligned_called++;
-  stats.last_align = static_cast<int>(a);
-  stats.last_size  = -1;
-}
-
-void operator delete(void* p, std::size_t n, std::align_val_t a) TEST_NOEXCEPT {
-  std::__libcpp_aligned_free(p);
-  stats.aligned_sized_called++;
-  stats.last_align = static_cast<int>(a);
-  stats.last_size  = n;
-}
-#endif
-
-void test_libcpp_dealloc() {
-  void* p = nullptr;
-#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
-  std::size_t over_align_val = __STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2;
-#else
-  std::size_t over_align_val = TEST_ALIGNOF(std::max_align_t) * 2;
-#endif
-  std::size_t under_align_val = TEST_ALIGNOF(int);
-  std::size_t with_size_val   = 2;
-
-  {
-    std::__libcpp_deallocate_unsized<char>(static_cast<char*>(p), under_align_val);
-    assert(stats.expect_plain());
-  }
-  stats.reset();
-
-#if defined(NO_SIZE) && defined(NO_ALIGN)
-  {
-    std::__libcpp_deallocate<char>(static_cast<char*>(p), std::__element_count(with_size_val), over_align_val);
-    assert(stats.expect_plain());
-  }
-  stats.reset();
-#elif defined(NO_SIZE)
-  {
-    std::__libcpp_deallocate<char>(static_cast<char*>(p), std::__element_count(with_size_val), over_align_val);
-    assert(stats.expect_align(over_align_val));
-  }
-  stats.reset();
-#elif defined(NO_ALIGN)
-  {
-    std::__libcpp_deallocate<char>(static_cast<char*>(p), std::__element_count(with_size_val), over_align_val);
-    assert(stats.expect_size(with_size_val));
-  }
-  stats.reset();
-#else
-  {
-    std::__libcpp_deallocate<char>(static_cast<char*>(p), std::__element_count(with_size_val), over_align_val);
-    assert(stats.expect_size_align(with_size_val, over_align_val));
-  }
-  stats.reset();
-  {
-    std::__libcpp_deallocate_unsized<char>(static_cast<char*>(p), over_align_val);
-    assert(stats.expect_align(over_align_val));
-  }
-  stats.reset();
-  {
-    std::__libcpp_deallocate<char>(static_cast<char*>(p), std::__element_count(with_size_val), under_align_val);
-    assert(stats.expect_size(with_size_val));
-  }
-  stats.reset();
-#endif
-}
-
-struct TEST_ALIGNAS(128) AlignedType {
-  AlignedType() : elem(0) {}
-  TEST_ALIGNAS(128) char elem;
-};
-
-void test_allocator_and_new_match() {
-  stats.reset();
-#if defined(NO_SIZE) && defined(NO_ALIGN)
-  {
-    int* x = DoNotOptimize(new int(42));
-    delete x;
-    assert(stats.expect_plain());
-  }
-  stats.reset();
-  {
-    AlignedType* a = DoNotOptimize(new AlignedType());
-    delete a;
-    assert(stats.expect_plain());
-  }
-  stats.reset();
-#elif defined(NO_SIZE)
-  stats.reset();
-#  if TEST_STD_VER >= 11
-  {
-    int* x = DoNotOptimize(new int(42));
-    delete x;
-    assert(stats.expect_plain());
-  }
-#  endif
-  stats.reset();
-  {
-    AlignedType* a = DoNotOptimize(new AlignedType());
-    delete a;
-    assert(stats.expect_align(TEST_ALIGNOF(AlignedType)));
-  }
-  stats.reset();
-#elif defined(NO_ALIGN)
-  stats.reset();
-  {
-    int* x = DoNotOptimize(new int(42));
-    delete x;
-    assert(stats.expect_size(sizeof(int)));
-  }
-  stats.reset();
-  {
-    AlignedType* a = DoNotOptimize(new AlignedType());
-    delete a;
-    assert(stats.expect_size(sizeof(AlignedType)));
-  }
-  stats.reset();
-#else
-  stats.reset();
-  {
-    int* x = DoNotOptimize(new int(42));
-    delete x;
-    assert(stats.expect_size(sizeof(int)));
-  }
-  stats.reset();
-  {
-    AlignedType* a = DoNotOptimize(new AlignedType());
-    delete a;
-    assert(stats.expect_size_align(sizeof(AlignedType), TEST_ALIGNOF(AlignedType)));
-  }
-  stats.reset();
-#endif
-}
-
-int main(int, char**) {
-  test_libcpp_dealloc();
-  test_allocator_and_new_match();
-
-  return 0;
-}

diff  --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.capacity/max_size.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.capacity/max_size.pass.cpp
index ee01f8eb1dfe43..d52ef42fda807a 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.capacity/max_size.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.capacity/max_size.pass.cpp
@@ -13,6 +13,7 @@
 // size_type max_size() const noexcept;
 
 #include <cassert>
+#include <cstddef>
 #include <deque>
 #include <flat_map>
 #include <functional>
@@ -50,7 +51,7 @@ constexpr bool test() {
     LIBCPP_ASSERT(c.max_size() == 10);
   }
   {
-    using A = limited_allocator<int, (size_t)-1>;
+    using A = limited_allocator<int, (std::size_t)-1>;
     using C = std::flat_map<int, int, std::less<int>, std::vector<int, A>, std::vector<int, A>>;
     ASSERT_SAME_TYPE(C::
diff erence_type, std::ptr
diff _t);
     ASSERT_SAME_TYPE(C::size_type, std::size_t);

diff  --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.capacity/max_size.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.capacity/max_size.pass.cpp
index fc35fec10cd956..241fd362d639bb 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.capacity/max_size.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.capacity/max_size.pass.cpp
@@ -15,6 +15,7 @@
 // size_type max_size() const noexcept;
 
 #include <cassert>
+#include <cstddef>
 #include <deque>
 #include <flat_map>
 #include <functional>
@@ -52,7 +53,7 @@ constexpr bool test() {
     LIBCPP_ASSERT(c.max_size() == 10);
   }
   {
-    using A = limited_allocator<int, (size_t)-1>;
+    using A = limited_allocator<int, (std::size_t)-1>;
     using C = std::flat_multimap<int, int, std::less<int>, std::vector<int, A>, std::vector<int, A>>;
     ASSERT_SAME_TYPE(C::
diff erence_type, std::ptr
diff _t);
     ASSERT_SAME_TYPE(C::size_type, std::size_t);

diff  --git a/libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.capacity/max_size.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.capacity/max_size.pass.cpp
index fb9c38f592262b..e912abbe272178 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.capacity/max_size.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.capacity/max_size.pass.cpp
@@ -13,6 +13,7 @@
 // size_type max_size() const noexcept;
 
 #include <cassert>
+#include <cstddef>
 #include <deque>
 #include <flat_set>
 #include <functional>
@@ -37,7 +38,7 @@ constexpr bool test() {
     LIBCPP_ASSERT(c.max_size() == 10);
   }
   {
-    using A = limited_allocator<int, (size_t)-1>;
+    using A = limited_allocator<int, (std::size_t)-1>;
     using C = std::flat_multiset<int, std::less<int>, std::vector<int, A>>;
     ASSERT_SAME_TYPE(C::
diff erence_type, std::ptr
diff _t);
     ASSERT_SAME_TYPE(C::size_type, std::size_t);

diff  --git a/libcxx/test/std/containers/container.adaptors/flat.set/flat.set.capacity/max_size.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.set/flat.set.capacity/max_size.pass.cpp
index e2f52ab458c4ca..de1151f883f5dd 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.set/flat.set.capacity/max_size.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.set/flat.set.capacity/max_size.pass.cpp
@@ -13,6 +13,7 @@
 // size_type max_size() const noexcept;
 
 #include <cassert>
+#include <cstddef>
 #include <deque>
 #include <flat_set>
 #include <functional>
@@ -37,7 +38,7 @@ constexpr bool test() {
     LIBCPP_ASSERT(c.max_size() == 10);
   }
   {
-    using A = limited_allocator<int, (size_t)-1>;
+    using A = limited_allocator<int, (std::size_t)-1>;
     using C = std::flat_set<int, std::less<int>, std::vector<int, A>>;
     ASSERT_SAME_TYPE(C::
diff erence_type, std::ptr
diff _t);
     ASSERT_SAME_TYPE(C::size_type, std::size_t);

diff  --git a/libcxx/test/std/language.support/support.dynamic/hardware_inference_size.compile.pass.cpp b/libcxx/test/std/language.support/support.dynamic/hardware_inference_size.compile.pass.cpp
index aed3d42161bae8..df775577202e3b 100644
--- a/libcxx/test/std/language.support/support.dynamic/hardware_inference_size.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/hardware_inference_size.compile.pass.cpp
@@ -8,6 +8,7 @@
 
 // UNSUPPORTED: c++03, c++11, c++14
 
+#include <cstddef>
 #include <new>
 
 #include "test_macros.h"

diff  --git a/libcxx/test/std/numerics/numarray/template.valarray/valarray.cons/size.pass.cpp b/libcxx/test/std/numerics/numarray/template.valarray/valarray.cons/size.pass.cpp
index 21d4ee15f57c63..fd7b903116c753 100644
--- a/libcxx/test/std/numerics/numarray/template.valarray/valarray.cons/size.pass.cpp
+++ b/libcxx/test/std/numerics/numarray/template.valarray/valarray.cons/size.pass.cpp
@@ -12,8 +12,9 @@
 
 // explicit valarray(size_t);
 
-#include <valarray>
 #include <cassert>
+#include <cstdint>
+#include <valarray>
 
 #include "test_macros.h"
 
@@ -24,7 +25,7 @@ struct S {
     static std::size_t cnt_dtor;
 };
 
-size_t S::cnt_dtor = 0;
+std::size_t S::cnt_dtor = 0;
 
 int main(int, char**)
 {

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/pointer_destruction.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/pointer_destruction.pass.cpp
index 184a008e2472a5..4fd9df297f5745 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/pointer_destruction.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/pointer_destruction.pass.cpp
@@ -15,12 +15,13 @@
 // XFAIL: FROZEN-CXX03-HEADERS-FIXME
 
 #include <cassert>
+#include <cstddef>
 #include <memory>
 #include <utility>
 
 #include "test_macros.h"
 
-static size_t pointer_count = 0;
+static std::size_t pointer_count = 0;
 
 template <class T>
 struct Pointer {


        


More information about the libcxx-commits mailing list