[libcxx-commits] [libcxx] [libcxxabi] [libc++] Granularize the <new> header (PR #119270)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Dec 11 10:45:26 PST 2024


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/119270

>From a501d16f131e5db9aefb6ab5b96a8aab2f7c3f84 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Mon, 9 Dec 2024 14:33:21 -0500
Subject: [PATCH 1/6] [libc++] Granularize the <new> header

---
 libcxx/include/CMakeLists.txt                 |   9 +
 libcxx/include/__memory/allocator.h           |   1 +
 .../include/__memory/builtin_new_allocator.h  |   1 +
 libcxx/include/__memory/shared_ptr.h          |   1 +
 .../__memory/uninitialized_algorithms.h       |   1 +
 libcxx/include/__new/align_val_t.h            |  30 ++
 libcxx/include/__new/allocate.h               | 101 +++++++
 libcxx/include/__new/destroying_delete_t.h    |  30 ++
 libcxx/include/__new/exceptions.h             |  74 +++++
 libcxx/include/__new/interference_size.h      |  34 +++
 libcxx/include/__new/launder.h                |  36 +++
 libcxx/include/__new/new_handler.h            |  29 ++
 libcxx/include/__new/nothrow_t.h              |  30 ++
 libcxx/include/__new/operators.h              | 100 ++++++
 libcxx/include/__utility/small_buffer.h       |   1 +
 libcxx/include/future                         |   1 +
 libcxx/include/module.modulemap               |  10 +
 libcxx/include/new                            | 284 +-----------------
 18 files changed, 503 insertions(+), 270 deletions(-)
 create mode 100644 libcxx/include/__new/align_val_t.h
 create mode 100644 libcxx/include/__new/allocate.h
 create mode 100644 libcxx/include/__new/destroying_delete_t.h
 create mode 100644 libcxx/include/__new/exceptions.h
 create mode 100644 libcxx/include/__new/interference_size.h
 create mode 100644 libcxx/include/__new/launder.h
 create mode 100644 libcxx/include/__new/new_handler.h
 create mode 100644 libcxx/include/__new/nothrow_t.h
 create mode 100644 libcxx/include/__new/operators.h

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 561ce4b42fb250..c9ba28ad59b673 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -581,6 +581,15 @@ set(files
   __mutex/once_flag.h
   __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/interference_size.h
+  __new/launder.h
+  __new/new_handler.h
+  __new/nothrow_t.h
+  __new/operators.h
   __node_handle
   __numeric/accumulate.h
   __numeric/adjacent_difference.h
diff --git a/libcxx/include/__memory/allocator.h b/libcxx/include/__memory/allocator.h
index ddb4179940b8b1..1fcaf6402667e1 100644
--- a/libcxx/include/__memory/allocator.h
+++ b/libcxx/include/__memory/allocator.h
@@ -12,6 +12,7 @@
 
 #include <__config>
 #include <__cstddef/ptrdiff_t.h>
+#include <__cstddef/size_t.h>
 #include <__memory/addressof.h>
 #include <__memory/allocate_at_least.h>
 #include <__memory/allocator_traits.h>
diff --git a/libcxx/include/__memory/builtin_new_allocator.h b/libcxx/include/__memory/builtin_new_allocator.h
index 128288efb05bc1..b1611b12bff03e 100644
--- a/libcxx/include/__memory/builtin_new_allocator.h
+++ b/libcxx/include/__memory/builtin_new_allocator.h
@@ -10,6 +10,7 @@
 #define _LIBCPP___MEMORY_BUILTIN_NEW_ALLOCATOR_H
 
 #include <__config>
+#include <__cstddef/size_t.h>
 #include <__memory/unique_ptr.h>
 #include <new>
 
diff --git a/libcxx/include/__memory/shared_ptr.h b/libcxx/include/__memory/shared_ptr.h
index 5c34f2efc5730e..4fa75af4ccc86d 100644
--- a/libcxx/include/__memory/shared_ptr.h
+++ b/libcxx/include/__memory/shared_ptr.h
@@ -43,6 +43,7 @@
 #include <__type_traits/is_bounded_array.h>
 #include <__type_traits/is_constructible.h>
 #include <__type_traits/is_convertible.h>
+#include <__type_traits/is_function.h>
 #include <__type_traits/is_reference.h>
 #include <__type_traits/is_same.h>
 #include <__type_traits/is_unbounded_array.h>
diff --git a/libcxx/include/__memory/uninitialized_algorithms.h b/libcxx/include/__memory/uninitialized_algorithms.h
index 71c7ed94fec13e..25d192c7718857 100644
--- a/libcxx/include/__memory/uninitialized_algorithms.h
+++ b/libcxx/include/__memory/uninitialized_algorithms.h
@@ -15,6 +15,7 @@
 #include <__algorithm/unwrap_iter.h>
 #include <__algorithm/unwrap_range.h>
 #include <__config>
+#include <__cstddef/size_t.h>
 #include <__iterator/iterator_traits.h>
 #include <__iterator/reverse_iterator.h>
 #include <__memory/addressof.h>
diff --git a/libcxx/include/__new/align_val_t.h b/libcxx/include/__new/align_val_t.h
new file mode 100644
index 00000000000000..ffb4e36a8bcd88
--- /dev/null
+++ b/libcxx/include/__new/align_val_t.h
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_ALIGN_VAL_T_H
+#define _LIBCPP___NEW_ALIGN_VAL_T_H
+
+#include <__config>
+#include <__cstddef/size_t.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+// purposefully not using versioning namespace
+namespace std {
+#if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION && !defined(_LIBCPP_ABI_VCRUNTIME)
+#  ifndef _LIBCPP_CXX03_LANG
+enum class align_val_t : size_t {};
+#  else
+enum align_val_t { __zero = 0, __max = (size_t)-1 };
+#  endif
+#endif
+} // namespace std
+
+#endif // _LIBCPP___NEW_ALIGN_VAL_T_H
diff --git a/libcxx/include/__new/allocate.h b/libcxx/include/__new/allocate.h
new file mode 100644
index 00000000000000..7ea7662c817ad4
--- /dev/null
+++ b/libcxx/include/__new/allocate.h
@@ -0,0 +1,101 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <__new/operators.h> // for _LIBCPP_HAS_SIZED_DEALLOCATION
+
+#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... _Args>
+_LIBCPP_HIDE_FROM_ABI void* __libcpp_operator_new(_Args... __args) {
+#if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete)
+  return __builtin_operator_new(__args...);
+#else
+  return ::operator new(__args...);
+#endif
+}
+
+template <class... _Args>
+_LIBCPP_HIDE_FROM_ABI void __libcpp_operator_delete(_Args... __args) _NOEXCEPT {
+#if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete)
+  __builtin_operator_delete(__args...);
+#else
+  ::operator delete(__args...);
+#endif
+}
+
+inline _LIBCPP_HIDE_FROM_ABI void* __libcpp_allocate(size_t __size, size_t __align) {
+#if _LIBCPP_HAS_ALIGNED_ALLOCATION
+  if (__is_overaligned_for_new(__align)) {
+    const align_val_t __align_val = static_cast<align_val_t>(__align);
+    return __libcpp_operator_new(__size, __align_val);
+  }
+#endif
+
+  (void)__align;
+  return __libcpp_operator_new(__size);
+}
+
+template <class... _Args>
+_LIBCPP_HIDE_FROM_ABI void __do_deallocate_handle_size(void* __ptr, size_t __size, _Args... __args) _NOEXCEPT {
+#if !_LIBCPP_HAS_SIZED_DEALLOCATION
+  (void)__size;
+  return std::__libcpp_operator_delete(__ptr, __args...);
+#else
+  return std::__libcpp_operator_delete(__ptr, __size, __args...);
+#endif
+}
+
+inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate(void* __ptr, size_t __size, size_t __align) _NOEXCEPT {
+#if !_LIBCPP_HAS_ALIGNED_ALLOCATION
+  (void)__align;
+  return __do_deallocate_handle_size(__ptr, __size);
+#else
+  if (__is_overaligned_for_new(__align)) {
+    const align_val_t __align_val = static_cast<align_val_t>(__align);
+    return __do_deallocate_handle_size(__ptr, __size, __align_val);
+  } else {
+    return __do_deallocate_handle_size(__ptr, __size);
+  }
+#endif
+}
+
+inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate_unsized(void* __ptr, size_t __align) _NOEXCEPT {
+#if !_LIBCPP_HAS_ALIGNED_ALLOCATION
+  (void)__align;
+  return __libcpp_operator_delete(__ptr);
+#else
+  if (__is_overaligned_for_new(__align)) {
+    const align_val_t __align_val = static_cast<align_val_t>(__align);
+    return __libcpp_operator_delete(__ptr, __align_val);
+  } else {
+    return __libcpp_operator_delete(__ptr);
+  }
+#endif
+}
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___NEW_ALLOCATE_H
diff --git a/libcxx/include/__new/destroying_delete_t.h b/libcxx/include/__new/destroying_delete_t.h
new file mode 100644
index 00000000000000..7fca4f6c68b212
--- /dev/null
+++ b/libcxx/include/__new/destroying_delete_t.h
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_DESTROYING_DELETE_T_H
+#define _LIBCPP___NEW_DESTROYING_DELETE_T_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 20
+// purposefully not using versioning namespace
+namespace std {
+// Enable the declaration even if the compiler doesn't support the language
+// feature.
+struct destroying_delete_t {
+  explicit destroying_delete_t() = default;
+};
+inline constexpr destroying_delete_t destroying_delete{};
+} // namespace std
+#endif
+
+#endif // _LIBCPP___NEW_DESTROYING_DELETE_T_H
diff --git a/libcxx/include/__new/exceptions.h b/libcxx/include/__new/exceptions.h
new file mode 100644
index 00000000000000..053feecb036787
--- /dev/null
+++ b/libcxx/include/__new/exceptions.h
@@ -0,0 +1,74 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_EXCEPTIONS_H
+#define _LIBCPP___NEW_EXCEPTIONS_H
+
+#include <__config>
+#include <__exception/exception.h>
+#include <__verbose_abort>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+// purposefully not using versioning namespace
+namespace std {
+#if !defined(_LIBCPP_ABI_VCRUNTIME)
+
+class _LIBCPP_EXPORTED_FROM_ABI bad_alloc : public exception {
+public:
+  bad_alloc() _NOEXCEPT;
+  _LIBCPP_HIDE_FROM_ABI bad_alloc(const bad_alloc&) _NOEXCEPT            = default;
+  _LIBCPP_HIDE_FROM_ABI bad_alloc& operator=(const bad_alloc&) _NOEXCEPT = default;
+  ~bad_alloc() _NOEXCEPT override;
+  const char* what() const _NOEXCEPT override;
+};
+
+class _LIBCPP_EXPORTED_FROM_ABI bad_array_new_length : public bad_alloc {
+public:
+  bad_array_new_length() _NOEXCEPT;
+  _LIBCPP_HIDE_FROM_ABI bad_array_new_length(const bad_array_new_length&) _NOEXCEPT            = default;
+  _LIBCPP_HIDE_FROM_ABI bad_array_new_length& operator=(const bad_array_new_length&) _NOEXCEPT = default;
+  ~bad_array_new_length() _NOEXCEPT override;
+  const char* what() const _NOEXCEPT override;
+};
+
+#elif defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0 // !_LIBCPP_ABI_VCRUNTIME
+
+// When _HAS_EXCEPTIONS == 0, these complete definitions are needed,
+// since they would normally be provided in vcruntime_exception.h
+class bad_alloc : public exception {
+public:
+  bad_alloc() noexcept : exception("bad allocation") {}
+
+private:
+  friend class bad_array_new_length;
+
+  bad_alloc(char const* const __message) noexcept : exception(__message) {}
+};
+
+class bad_array_new_length : public bad_alloc {
+public:
+  bad_array_new_length() noexcept : bad_alloc("bad array new length") {}
+};
+
+#endif // defined(_LIBCPP_ABI_VCRUNTIME) && defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0
+
+[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void __throw_bad_alloc(); // not in C++ spec
+
+[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_array_new_length() {
+#if _LIBCPP_HAS_EXCEPTIONS
+  throw bad_array_new_length();
+#else
+  _LIBCPP_VERBOSE_ABORT("bad_array_new_length was thrown in -fno-exceptions mode");
+#endif
+}
+} // namespace std
+
+#endif // _LIBCPP___NEW_EXCEPTIONS_H
diff --git a/libcxx/include/__new/interference_size.h b/libcxx/include/__new/interference_size.h
new file mode 100644
index 00000000000000..d326c43a332034
--- /dev/null
+++ b/libcxx/include/__new/interference_size.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_INTERFERENCE_SIZE_H
+#define _LIBCPP___NEW_INTERFERENCE_SIZE_H
+
+#include <__config>
+#include <__cstddef/size_t.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 17
+
+#  if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
+
+inline constexpr size_t hardware_destructive_interference_size  = __GCC_DESTRUCTIVE_SIZE;
+inline constexpr size_t hardware_constructive_interference_size = __GCC_CONSTRUCTIVE_SIZE;
+
+#  endif // defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
+
+#endif // _LIBCPP_STD_VER >= 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___NEW_INTERFERENCE_SIZE_H
diff --git a/libcxx/include/__new/launder.h b/libcxx/include/__new/launder.h
new file mode 100644
index 00000000000000..83d80015913d96
--- /dev/null
+++ b/libcxx/include/__new/launder.h
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_LAUNDER_H
+#define _LIBCPP___NEW_LAUNDER_H
+
+#include <__config>
+#include <__type_traits/is_function.h>
+#include <__type_traits/is_void.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+template <class _Tp>
+[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT {
+  static_assert(!(is_function<_Tp>::value), "can't launder functions");
+  static_assert(!is_void<_Tp>::value, "can't launder cv-void");
+  return __builtin_launder(__p);
+}
+
+#if _LIBCPP_STD_VER >= 17
+template <class _Tp>
+[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp* launder(_Tp* __p) noexcept {
+  return std::__launder(__p);
+}
+#endif
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___NEW_LAUNDER_H
diff --git a/libcxx/include/__new/new_handler.h b/libcxx/include/__new/new_handler.h
new file mode 100644
index 00000000000000..c9afdab45afc13
--- /dev/null
+++ b/libcxx/include/__new/new_handler.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_NEW_HANDLER_H
+#define _LIBCPP___NEW_NEW_HANDLER_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if defined(_LIBCPP_ABI_VCRUNTIME)
+#  include <new.h>
+#else
+// purposefully not using versioning namespace
+namespace std {
+typedef void (*new_handler)();
+_LIBCPP_EXPORTED_FROM_ABI new_handler set_new_handler(new_handler) _NOEXCEPT;
+_LIBCPP_EXPORTED_FROM_ABI new_handler get_new_handler() _NOEXCEPT;
+} // namespace std
+#endif // _LIBCPP_ABI_VCRUNTIME
+
+#endif // _LIBCPP___NEW_NEW_HANDLER_H
diff --git a/libcxx/include/__new/nothrow_t.h b/libcxx/include/__new/nothrow_t.h
new file mode 100644
index 00000000000000..09c2d03f66ccc4
--- /dev/null
+++ b/libcxx/include/__new/nothrow_t.h
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_NOTHROW_T_H
+#define _LIBCPP___NEW_NOTHROW_T_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if defined(_LIBCPP_ABI_VCRUNTIME)
+#  include <new.h>
+#else
+// purposefully not using versioning namespace
+namespace std {
+struct _LIBCPP_EXPORTED_FROM_ABI nothrow_t {
+  explicit nothrow_t() = default;
+};
+extern _LIBCPP_EXPORTED_FROM_ABI const nothrow_t nothrow;
+} // namespace std
+#endif // _LIBCPP_ABI_VCRUNTIME
+
+#endif // _LIBCPP___NEW_NOTHROW_T_H
diff --git a/libcxx/include/__new/operators.h b/libcxx/include/__new/operators.h
new file mode 100644
index 00000000000000..411f956bdda156
--- /dev/null
+++ b/libcxx/include/__new/operators.h
@@ -0,0 +1,100 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_OPERATORS_H
+#define _LIBCPP___NEW_OPERATORS_H
+
+#include <__config>
+#include <__cstddef/size_t.h>
+#include <__new/align_val_t.h>
+#include <__new/exceptions.h>
+#include <__new/nothrow_t.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if defined(_LIBCPP_CXX03_LANG)
+#  define _THROW_BAD_ALLOC throw(std::bad_alloc)
+#else
+#  define _THROW_BAD_ALLOC
+#endif
+
+#if defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309L
+#  define _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION 1
+#else
+#  define _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION 0
+#endif
+
+#if _LIBCPP_STD_VER >= 14 || _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION
+#  define _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION 1
+#else
+#  define _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION 0
+#endif
+
+#if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION && _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION
+#  define _LIBCPP_HAS_SIZED_DEALLOCATION 1
+#else
+#  define _LIBCPP_HAS_SIZED_DEALLOCATION 0
+#endif
+
+#if defined(_LIBCPP_ABI_VCRUNTIME)
+#  include <new.h>
+#else
+[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC;
+[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT
+    _LIBCPP_NOALIAS;
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
+#  if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
+#  endif
+
+[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC;
+[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT
+    _LIBCPP_NOALIAS;
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
+#  if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT;
+#  endif
+
+#  if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
+[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
+[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
+operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
+#    if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
+#    endif
+
+[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
+operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
+[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
+operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
+#    if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
+#    endif
+#  endif
+
+[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void*
+operator new(std::size_t, void* __p) _NOEXCEPT {
+  return __p;
+}
+[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void*
+operator new[](std::size_t, void* __p) _NOEXCEPT {
+  return __p;
+}
+inline _LIBCPP_HIDE_FROM_ABI void operator delete(void*, void*) _NOEXCEPT {}
+inline _LIBCPP_HIDE_FROM_ABI void operator delete[](void*, void*) _NOEXCEPT {}
+#endif
+
+#endif // _LIBCPP___NEW_OPERATORS_H
diff --git a/libcxx/include/__utility/small_buffer.h b/libcxx/include/__utility/small_buffer.h
index b44b37e90e7653..405c0aed459632 100644
--- a/libcxx/include/__utility/small_buffer.h
+++ b/libcxx/include/__utility/small_buffer.h
@@ -11,6 +11,7 @@
 
 #include <__config>
 #include <__cstddef/byte.h>
+#include <__cstddef/size_t.h>
 #include <__memory/construct_at.h>
 #include <__type_traits/decay.h>
 #include <__type_traits/is_trivially_constructible.h>
diff --git a/libcxx/include/future b/libcxx/include/future
index 62f59682d404d3..dacf2c10a1990b 100644
--- a/libcxx/include/future
+++ b/libcxx/include/future
@@ -373,6 +373,7 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
 #    include <__chrono/steady_clock.h>
 #    include <__chrono/time_point.h>
 #    include <__condition_variable/condition_variable.h>
+#    include <__cstddef/nullptr_t.h>
 #    include <__exception/exception_ptr.h>
 #    include <__memory/addressof.h>
 #    include <__memory/allocator.h>
diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index 81621f467aba71..db2d79604b02e2 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -1603,6 +1603,16 @@ module std [system] {
 
   module new {
     header "new"
+    module align_val_t          { header "__new/align_val_t.h" }
+    module allocate             { header "__new/allocate.h" }
+    module destroying_delete_t  { header "__new/destroying_delete_t.h" }
+    module exceptions           { header "__new/exceptions.h" }
+    module interference_size    { header "__new/interference_size.h" }
+    module launder              { header "__new/launder.h" }
+    module new_handler          { header "__new/new_handler.h" }
+    module nothrow_t            { header "__new/nothrow_t.h" }
+    module operators            { header "__new/operators.h" }
+
     export *
   }
 
diff --git a/libcxx/include/new b/libcxx/include/new
index 8bb7b300d08bce..3cadbf1571e7f5 100644
--- a/libcxx/include/new
+++ b/libcxx/include/new
@@ -89,285 +89,29 @@ void  operator delete[](void* ptr, void*) noexcept;
 #if 0
 #else // 0
 #  include <__config>
-#  include <__cstddef/max_align_t.h>
-#  include <__cstddef/size_t.h>
-#  include <__exception/exception.h>
-#  include <__type_traits/is_function.h>
-#  include <__type_traits/is_void.h>
-#  include <__verbose_abort>
-#  include <version>
-
-#  if defined(_LIBCPP_ABI_VCRUNTIME)
-#    include <new.h>
-#  endif
-
-#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#    pragma GCC system_header
-#  endif
-
-#  if defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309L
-#    define _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION 1
-#  else
-#    define _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION 0
-#  endif
-
-#  if _LIBCPP_STD_VER >= 14 || _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION
-#    define _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION 1
-#  else
-#    define _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION 0
-#  endif
-
-#  if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION && _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION
-#    define _LIBCPP_HAS_SIZED_DEALLOCATION 1
-#  else
-#    define _LIBCPP_HAS_SIZED_DEALLOCATION 0
-#  endif
-
-namespace std // purposefully not using versioning namespace
-{
-
-#  if !defined(_LIBCPP_ABI_VCRUNTIME)
-struct _LIBCPP_EXPORTED_FROM_ABI nothrow_t {
-  explicit nothrow_t() = default;
-};
-extern _LIBCPP_EXPORTED_FROM_ABI const nothrow_t nothrow;
-
-class _LIBCPP_EXPORTED_FROM_ABI bad_alloc : public exception {
-public:
-  bad_alloc() _NOEXCEPT;
-  _LIBCPP_HIDE_FROM_ABI bad_alloc(const bad_alloc&) _NOEXCEPT            = default;
-  _LIBCPP_HIDE_FROM_ABI bad_alloc& operator=(const bad_alloc&) _NOEXCEPT = default;
-  ~bad_alloc() _NOEXCEPT override;
-  const char* what() const _NOEXCEPT override;
-};
-
-class _LIBCPP_EXPORTED_FROM_ABI bad_array_new_length : public bad_alloc {
-public:
-  bad_array_new_length() _NOEXCEPT;
-  _LIBCPP_HIDE_FROM_ABI bad_array_new_length(const bad_array_new_length&) _NOEXCEPT            = default;
-  _LIBCPP_HIDE_FROM_ABI bad_array_new_length& operator=(const bad_array_new_length&) _NOEXCEPT = default;
-  ~bad_array_new_length() _NOEXCEPT override;
-  const char* what() const _NOEXCEPT override;
-};
-
-typedef void (*new_handler)();
-_LIBCPP_EXPORTED_FROM_ABI new_handler set_new_handler(new_handler) _NOEXCEPT;
-_LIBCPP_EXPORTED_FROM_ABI new_handler get_new_handler() _NOEXCEPT;
-
-#  elif defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0 // !_LIBCPP_ABI_VCRUNTIME
-
-// When _HAS_EXCEPTIONS == 0, these complete definitions are needed,
-// since they would normally be provided in vcruntime_exception.h
-class bad_alloc : public exception {
-public:
-  bad_alloc() noexcept : exception("bad allocation") {}
-
-private:
-  friend class bad_array_new_length;
+#  include <__new/align_val_t.h>
+#  include <__new/allocate.h>
+#  include <__new/exceptions.h>
+#  include <__new/new_handler.h>
+#  include <__new/nothrow_t.h>
+#  include <__new/operators.h>
 
-  bad_alloc(char const* const __message) noexcept : exception(__message) {}
-};
-
-class bad_array_new_length : public bad_alloc {
-public:
-  bad_array_new_length() noexcept : bad_alloc("bad array new length") {}
-};
-#  endif // defined(_LIBCPP_ABI_VCRUNTIME) && defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0
-
-[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void __throw_bad_alloc(); // not in C++ spec
-
-[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_array_new_length() {
-#  if _LIBCPP_HAS_EXCEPTIONS
-  throw bad_array_new_length();
-#  else
-  _LIBCPP_VERBOSE_ABORT("bad_array_new_length was thrown in -fno-exceptions mode");
-#  endif
-}
-
-#  if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION && !defined(_LIBCPP_ABI_VCRUNTIME)
-#    ifndef _LIBCPP_CXX03_LANG
-enum class align_val_t : size_t {};
-#    else
-enum align_val_t { __zero = 0, __max = (size_t)-1 };
-#    endif
+#  if _LIBCPP_STD_VER >= 17
+#    include <__new/interference_size.h>
+#    include <__new/launder.h>
 #  endif
 
 #  if _LIBCPP_STD_VER >= 20
-// Enable the declaration even if the compiler doesn't support the language
-// feature.
-struct destroying_delete_t {
-  explicit destroying_delete_t() = default;
-};
-inline constexpr destroying_delete_t destroying_delete{};
-#  endif // _LIBCPP_STD_VER >= 20
-
-} // namespace std
-
-#  if defined(_LIBCPP_CXX03_LANG)
-#    define _THROW_BAD_ALLOC throw(std::bad_alloc)
-#  else
-#    define _THROW_BAD_ALLOC
-#  endif
-
-#  if !defined(_LIBCPP_ABI_VCRUNTIME)
-
-[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC;
-[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT
-    _LIBCPP_NOALIAS;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
-#    if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
-#    endif
-
-[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC;
-[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT
-    _LIBCPP_NOALIAS;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
-#    if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT;
-#    endif
-
-#    if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
-[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
-[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
-operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
-#      if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
-#      endif
-
-[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
-operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
-[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
-operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
-#      if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
-#      endif
-#    endif
-
-[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void*
-operator new(std::size_t, void* __p) _NOEXCEPT {
-  return __p;
-}
-[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void*
-operator new[](std::size_t, void* __p) _NOEXCEPT {
-  return __p;
-}
-inline _LIBCPP_HIDE_FROM_ABI void operator delete(void*, void*) _NOEXCEPT {}
-inline _LIBCPP_HIDE_FROM_ABI void operator delete[](void*, void*) _NOEXCEPT {}
-
-#  endif // !_LIBCPP_ABI_VCRUNTIME
-
-_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... _Args>
-_LIBCPP_HIDE_FROM_ABI void* __libcpp_operator_new(_Args... __args) {
-#  if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete)
-  return __builtin_operator_new(__args...);
-#  else
-  return ::operator new(__args...);
-#  endif
-}
-
-template <class... _Args>
-_LIBCPP_HIDE_FROM_ABI void __libcpp_operator_delete(_Args... __args) _NOEXCEPT {
-#  if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete)
-  __builtin_operator_delete(__args...);
-#  else
-  ::operator delete(__args...);
-#  endif
-}
-
-inline _LIBCPP_HIDE_FROM_ABI void* __libcpp_allocate(size_t __size, size_t __align) {
-#  if _LIBCPP_HAS_ALIGNED_ALLOCATION
-  if (__is_overaligned_for_new(__align)) {
-    const align_val_t __align_val = static_cast<align_val_t>(__align);
-    return __libcpp_operator_new(__size, __align_val);
-  }
-#  endif
-
-  (void)__align;
-  return __libcpp_operator_new(__size);
-}
-
-template <class... _Args>
-_LIBCPP_HIDE_FROM_ABI void __do_deallocate_handle_size(void* __ptr, size_t __size, _Args... __args) _NOEXCEPT {
-#  if !_LIBCPP_HAS_SIZED_DEALLOCATION
-  (void)__size;
-  return std::__libcpp_operator_delete(__ptr, __args...);
-#  else
-  return std::__libcpp_operator_delete(__ptr, __size, __args...);
-#  endif
-}
-
-inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate(void* __ptr, size_t __size, size_t __align) _NOEXCEPT {
-#  if !_LIBCPP_HAS_ALIGNED_ALLOCATION
-  (void)__align;
-  return __do_deallocate_handle_size(__ptr, __size);
-#  else
-  if (__is_overaligned_for_new(__align)) {
-    const align_val_t __align_val = static_cast<align_val_t>(__align);
-    return __do_deallocate_handle_size(__ptr, __size, __align_val);
-  } else {
-    return __do_deallocate_handle_size(__ptr, __size);
-  }
-#  endif
-}
-
-inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate_unsized(void* __ptr, size_t __align) _NOEXCEPT {
-#  if !_LIBCPP_HAS_ALIGNED_ALLOCATION
-  (void)__align;
-  return __libcpp_operator_delete(__ptr);
-#  else
-  if (__is_overaligned_for_new(__align)) {
-    const align_val_t __align_val = static_cast<align_val_t>(__align);
-    return __libcpp_operator_delete(__ptr, __align_val);
-  } else {
-    return __libcpp_operator_delete(__ptr);
-  }
+#    include <__new/destroying_delete_t.h>
 #  endif
-}
 
-template <class _Tp>
-[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT {
-  static_assert(!(is_function<_Tp>::value), "can't launder functions");
-  static_assert(!is_void<_Tp>::value, "can't launder cv-void");
-  return __builtin_launder(__p);
-}
+// feature-test macros
+#  include <version>
 
-#  if _LIBCPP_STD_VER >= 17
-template <class _Tp>
-[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp* launder(_Tp* __p) noexcept {
-  return std::__launder(__p);
-}
+#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#    pragma GCC system_header
 #  endif
 
-#  if _LIBCPP_STD_VER >= 17
-
-#    if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
-
-inline constexpr size_t hardware_destructive_interference_size  = __GCC_DESTRUCTIVE_SIZE;
-inline constexpr size_t hardware_constructive_interference_size = __GCC_CONSTRUCTIVE_SIZE;
-
-#    endif // defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
-
-#  endif // _LIBCPP_STD_VER >= 17
-
-_LIBCPP_END_NAMESPACE_STD
-
 #  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
 #    include <cstddef>
 #    include <cstdlib>

>From 80ee30368d93eafe95289b831352b5bf121db1ed Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Tue, 10 Dec 2024 15:48:49 -0500
Subject: [PATCH 2/6] Fix some CI issues

---
 libcxx/include/__hash_table                               | 2 +-
 .../alloc.errors/bad.alloc/bad_alloc.pass.cpp             | 3 ++-
 .../new.delete/new.delete.placement/new_array.pass.cpp    | 1 +
 .../support.dynamic/ptr.launder/launder.types.verify.cpp  | 8 ++++----
 .../allocator.members/allocate.size.pass.cpp              | 1 +
 5 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table
index a0c72f4c205413..fe7465a84c4024 100644
--- a/libcxx/include/__hash_table
+++ b/libcxx/include/__hash_table
@@ -26,6 +26,7 @@
 #include <__memory/pointer_traits.h>
 #include <__memory/swap_allocator.h>
 #include <__memory/unique_ptr.h>
+#include <__new/launder.h>
 #include <__type_traits/can_extract_key.h>
 #include <__type_traits/conditional.h>
 #include <__type_traits/enable_if.h>
@@ -46,7 +47,6 @@
 #include <__utility/swap.h>
 #include <cstring>
 #include <limits>
-#include <new> // __launder
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
diff --git a/libcxx/test/std/language.support/support.dynamic/alloc.errors/bad.alloc/bad_alloc.pass.cpp b/libcxx/test/std/language.support/support.dynamic/alloc.errors/bad.alloc/bad_alloc.pass.cpp
index a4016bff741390..9705513ae54b04 100644
--- a/libcxx/test/std/language.support/support.dynamic/alloc.errors/bad.alloc/bad_alloc.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/alloc.errors/bad.alloc/bad_alloc.pass.cpp
@@ -9,8 +9,9 @@
 // test bad_alloc
 
 #include <new>
-#include <type_traits>
 #include <cassert>
+#include <exception>
+#include <type_traits>
 
 #include "test_macros.h"
 
diff --git a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_array.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_array.pass.cpp
index e27fad95becb77..1f7b08ec641c31 100644
--- a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_array.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_array.pass.cpp
@@ -10,6 +10,7 @@
 
 #include <new>
 #include <cassert>
+#include <cstddef>
 
 #include "test_macros.h"
 
diff --git a/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.verify.cpp b/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.verify.cpp
index f8f04112fa82f1..cf93aee7526585 100644
--- a/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.verify.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.verify.cpp
@@ -26,11 +26,11 @@ int main(int, char**)
     (void) std::launder((               void *) nullptr);
     (void) std::launder((const          void *) nullptr);
     (void) std::launder((      volatile void *) nullptr);
-    (void) std::launder((const volatile void *) nullptr);  // expected-error-re at new:* 4 {{static assertion failed{{.*}}can't launder cv-void}}
-    // expected-error at new:* 0-4 {{void pointer argument to '__builtin_launder' is not allowed}}
+    (void) std::launder((const volatile void *) nullptr);  // expected-error-re@*:* 4 {{static assertion failed{{.*}}can't launder cv-void}}
+    // expected-error@*:* 0-4 {{void pointer argument to '__builtin_launder' is not allowed}}
 
-    (void) std::launder(foo);                              // expected-error-re at new:* 1 {{static assertion failed{{.*}}can't launder functions}}
-    // expected-error at new:* 0-1 {{function pointer argument to '__builtin_launder' is not allowed}}
+    (void) std::launder(foo);                              // expected-error-re@*:* 1 {{static assertion failed{{.*}}can't launder functions}}
+    // expected-error@*:* 0-1 {{function pointer argument to '__builtin_launder' is not allowed}}
 
   return 0;
 }
diff --git a/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
index 2b11bd7f48dd7f..eaeaaa50401e9a 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
@@ -14,6 +14,7 @@
 
 #include <memory>
 #include <cassert>
+#include <cstddef>
 #include <new>
 
 #include "test_macros.h"

>From a02468e4afee4b96adb390f6cff24407a96dbbe8 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Tue, 10 Dec 2024 15:52:57 -0500
Subject: [PATCH 3/6] Rename operators.h header to operator_new_delete.h

---
 libcxx/include/CMakeLists.txt                               | 2 +-
 libcxx/include/__new/allocate.h                             | 2 +-
 libcxx/include/__new/{operators.h => operator_new_delete.h} | 6 +++---
 libcxx/include/module.modulemap                             | 2 +-
 libcxx/include/new                                          | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)
 rename libcxx/include/__new/{operators.h => operator_new_delete.h} (96%)

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index c9ba28ad59b673..0f6276019e70af 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -589,7 +589,7 @@ set(files
   __new/launder.h
   __new/new_handler.h
   __new/nothrow_t.h
-  __new/operators.h
+  __new/operator_new_delete.h
   __node_handle
   __numeric/accumulate.h
   __numeric/adjacent_difference.h
diff --git a/libcxx/include/__new/allocate.h b/libcxx/include/__new/allocate.h
index 7ea7662c817ad4..6e3c02cbbac0f0 100644
--- a/libcxx/include/__new/allocate.h
+++ b/libcxx/include/__new/allocate.h
@@ -13,7 +13,7 @@
 #include <__cstddef/max_align_t.h>
 #include <__cstddef/size_t.h>
 #include <__new/align_val_t.h>
-#include <__new/operators.h> // for _LIBCPP_HAS_SIZED_DEALLOCATION
+#include <__new/operator_new_delete.h> // for _LIBCPP_HAS_SIZED_DEALLOCATION
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
diff --git a/libcxx/include/__new/operators.h b/libcxx/include/__new/operator_new_delete.h
similarity index 96%
rename from libcxx/include/__new/operators.h
rename to libcxx/include/__new/operator_new_delete.h
index 411f956bdda156..5096691023672a 100644
--- a/libcxx/include/__new/operators.h
+++ b/libcxx/include/__new/operator_new_delete.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _LIBCPP___NEW_OPERATORS_H
-#define _LIBCPP___NEW_OPERATORS_H
+#ifndef _LIBCPP___NEW_OPERATOR_NEW_DELETE_H
+#define _LIBCPP___NEW_OPERATOR_NEW_DELETE_H
 
 #include <__config>
 #include <__cstddef/size_t.h>
@@ -97,4 +97,4 @@ inline _LIBCPP_HIDE_FROM_ABI void operator delete(void*, void*) _NOEXCEPT {}
 inline _LIBCPP_HIDE_FROM_ABI void operator delete[](void*, void*) _NOEXCEPT {}
 #endif
 
-#endif // _LIBCPP___NEW_OPERATORS_H
+#endif // _LIBCPP___NEW_OPERATOR_NEW_DELETE_H
diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index db2d79604b02e2..dedda1f044b596 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -1611,7 +1611,7 @@ module std [system] {
     module launder              { header "__new/launder.h" }
     module new_handler          { header "__new/new_handler.h" }
     module nothrow_t            { header "__new/nothrow_t.h" }
-    module operators            { header "__new/operators.h" }
+    module operator_new_delete  { header "__new/operator_new_delete.h" }
 
     export *
   }
diff --git a/libcxx/include/new b/libcxx/include/new
index 3cadbf1571e7f5..f1896b27e05c36 100644
--- a/libcxx/include/new
+++ b/libcxx/include/new
@@ -94,7 +94,7 @@ void  operator delete[](void* ptr, void*) noexcept;
 #  include <__new/exceptions.h>
 #  include <__new/new_handler.h>
 #  include <__new/nothrow_t.h>
-#  include <__new/operators.h>
+#  include <__new/operator_new_delete.h>
 
 #  if _LIBCPP_STD_VER >= 17
 #    include <__new/interference_size.h>

>From 372928aeddb24679bf7fa215954e28650850edb7 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 11 Dec 2024 12:55:29 -0500
Subject: [PATCH 4/6] Fix CI issues

---
 libcxx/include/forward_list                          | 2 +-
 libcxx/include/list                                  | 2 +-
 libcxxabi/test/cxa_vec_new_overflow_PR41395.pass.cpp | 3 ++-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list
index bc95b30f441fac..23e8e51632171e 100644
--- a/libcxx/include/forward_list
+++ b/libcxx/include/forward_list
@@ -216,6 +216,7 @@ template <class T, class Allocator, class Predicate>
 #  include <__memory/pointer_traits.h>
 #  include <__memory/swap_allocator.h>
 #  include <__memory_resource/polymorphic_allocator.h>
+#  include <__new/launder.h>
 #  include <__ranges/access.h>
 #  include <__ranges/concepts.h>
 #  include <__ranges/container_compatible_range.h>
@@ -235,7 +236,6 @@ template <class T, class Allocator, class Predicate>
 #  include <__utility/move.h>
 #  include <__utility/swap.h>
 #  include <limits>
-#  include <new> // __launder
 #  include <version>
 
 // standard-mandated includes
diff --git a/libcxx/include/list b/libcxx/include/list
index 89863995379d9c..a9d14272742bd4 100644
--- a/libcxx/include/list
+++ b/libcxx/include/list
@@ -222,6 +222,7 @@ template <class T, class Allocator, class Predicate>
 #  include <__memory/pointer_traits.h>
 #  include <__memory/swap_allocator.h>
 #  include <__memory_resource/polymorphic_allocator.h>
+#  include <__new/launder.h>
 #  include <__ranges/access.h>
 #  include <__ranges/concepts.h>
 #  include <__ranges/container_compatible_range.h>
@@ -240,7 +241,6 @@ template <class T, class Allocator, class Predicate>
 #  include <__utility/swap.h>
 #  include <cstring>
 #  include <limits>
-#  include <new> // __launder
 #  include <version>
 
 // standard-mandated includes
diff --git a/libcxxabi/test/cxa_vec_new_overflow_PR41395.pass.cpp b/libcxxabi/test/cxa_vec_new_overflow_PR41395.pass.cpp
index b3ecf485d3951d..746dbaad053ef7 100644
--- a/libcxxabi/test/cxa_vec_new_overflow_PR41395.pass.cpp
+++ b/libcxxabi/test/cxa_vec_new_overflow_PR41395.pass.cpp
@@ -12,8 +12,9 @@
 // XFAIL: using-built-library-before-llvm-9
 
 #include "cxxabi.h"
-#include <new>
 #include <cassert>
+#include <cstddef>
+#include <new>
 
 void dummy_ctor(void*) { assert(false && "should not be called"); }
 void dummy_dtor(void*) { assert(false && "should not be called"); }

>From 2a22a4e424ac6a3da8491b7d9c48d62da8b3f12c Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 11 Dec 2024 13:04:27 -0500
Subject: [PATCH 5/6] Split placement-new and allocating new

---
 libcxx/include/CMakeLists.txt                 |  3 +-
 libcxx/include/__memory/construct_at.h        |  2 +-
 libcxx/include/__new/allocate.h               |  2 +-
 ...rator_new_delete.h => global_new_delete.h} | 17 ++--------
 libcxx/include/__new/placement_new_delete.h   | 34 +++++++++++++++++++
 libcxx/include/module.modulemap               |  3 +-
 libcxx/include/new                            |  3 +-
 7 files changed, 45 insertions(+), 19 deletions(-)
 rename libcxx/include/__new/{operator_new_delete.h => global_new_delete.h} (86%)
 create mode 100644 libcxx/include/__new/placement_new_delete.h

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 0f6276019e70af..10e5a15c855c81 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -585,11 +585,12 @@ set(files
   __new/allocate.h
   __new/destroying_delete_t.h
   __new/exceptions.h
+  __new/global_new_delete.h
   __new/interference_size.h
   __new/launder.h
   __new/new_handler.h
   __new/nothrow_t.h
-  __new/operator_new_delete.h
+  __new/placement_new_delete.h
   __node_handle
   __numeric/accumulate.h
   __numeric/adjacent_difference.h
diff --git a/libcxx/include/__memory/construct_at.h b/libcxx/include/__memory/construct_at.h
index d8c97467f54b9f..1f129d17970b19 100644
--- a/libcxx/include/__memory/construct_at.h
+++ b/libcxx/include/__memory/construct_at.h
@@ -14,12 +14,12 @@
 #include <__config>
 #include <__iterator/access.h>
 #include <__memory/addressof.h>
+#include <__new/placement_new_delete.h>
 #include <__type_traits/enable_if.h>
 #include <__type_traits/is_array.h>
 #include <__utility/declval.h>
 #include <__utility/forward.h>
 #include <__utility/move.h>
-#include <new>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
diff --git a/libcxx/include/__new/allocate.h b/libcxx/include/__new/allocate.h
index 6e3c02cbbac0f0..71dffc1776eff3 100644
--- a/libcxx/include/__new/allocate.h
+++ b/libcxx/include/__new/allocate.h
@@ -13,7 +13,7 @@
 #include <__cstddef/max_align_t.h>
 #include <__cstddef/size_t.h>
 #include <__new/align_val_t.h>
-#include <__new/operator_new_delete.h> // for _LIBCPP_HAS_SIZED_DEALLOCATION
+#include <__new/global_new_delete.h> // for _LIBCPP_HAS_SIZED_DEALLOCATION
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
diff --git a/libcxx/include/__new/operator_new_delete.h b/libcxx/include/__new/global_new_delete.h
similarity index 86%
rename from libcxx/include/__new/operator_new_delete.h
rename to libcxx/include/__new/global_new_delete.h
index 5096691023672a..7d0797e4832467 100644
--- a/libcxx/include/__new/operator_new_delete.h
+++ b/libcxx/include/__new/global_new_delete.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _LIBCPP___NEW_OPERATOR_NEW_DELETE_H
-#define _LIBCPP___NEW_OPERATOR_NEW_DELETE_H
+#ifndef _LIBCPP___NEW_GLOBAL_NEW_DELETE_H
+#define _LIBCPP___NEW_GLOBAL_NEW_DELETE_H
 
 #include <__config>
 #include <__cstddef/size_t.h>
@@ -84,17 +84,6 @@ _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t,
 _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
 #    endif
 #  endif
-
-[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void*
-operator new(std::size_t, void* __p) _NOEXCEPT {
-  return __p;
-}
-[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void*
-operator new[](std::size_t, void* __p) _NOEXCEPT {
-  return __p;
-}
-inline _LIBCPP_HIDE_FROM_ABI void operator delete(void*, void*) _NOEXCEPT {}
-inline _LIBCPP_HIDE_FROM_ABI void operator delete[](void*, void*) _NOEXCEPT {}
 #endif
 
-#endif // _LIBCPP___NEW_OPERATOR_NEW_DELETE_H
+#endif // _LIBCPP___NEW_GLOBAL_NEW_DELETE_H
diff --git a/libcxx/include/__new/placement_new_delete.h b/libcxx/include/__new/placement_new_delete.h
new file mode 100644
index 00000000000000..42c9f340367755
--- /dev/null
+++ b/libcxx/include/__new/placement_new_delete.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_PLACEMENT_NEW_DELETE_H
+#define _LIBCPP___NEW_PLACEMENT_NEW_DELETE_H
+
+#include <__config>
+#include <__cstddef/size_t.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if defined(_LIBCPP_ABI_VCRUNTIME)
+#  include <new.h>
+#else
+[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void*
+operator new(std::size_t, void* __p) _NOEXCEPT {
+  return __p;
+}
+[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void*
+operator new[](std::size_t, void* __p) _NOEXCEPT {
+  return __p;
+}
+inline _LIBCPP_HIDE_FROM_ABI void operator delete(void*, void*) _NOEXCEPT {}
+inline _LIBCPP_HIDE_FROM_ABI void operator delete[](void*, void*) _NOEXCEPT {}
+#endif
+
+#endif // _LIBCPP___NEW_PLACEMENT_NEW_DELETE_H
diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index dedda1f044b596..8d862e9f9ba361 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -1607,11 +1607,12 @@ module std [system] {
     module allocate             { header "__new/allocate.h" }
     module destroying_delete_t  { header "__new/destroying_delete_t.h" }
     module exceptions           { header "__new/exceptions.h" }
+    module global_new_delete    { header "__new/global_new_delete.h" }
     module interference_size    { header "__new/interference_size.h" }
     module launder              { header "__new/launder.h" }
     module new_handler          { header "__new/new_handler.h" }
     module nothrow_t            { header "__new/nothrow_t.h" }
-    module operator_new_delete  { header "__new/operator_new_delete.h" }
+    module placement_new_delete { header "__new/placement_new_delete.h" }
 
     export *
   }
diff --git a/libcxx/include/new b/libcxx/include/new
index f1896b27e05c36..8dd726f63a0e76 100644
--- a/libcxx/include/new
+++ b/libcxx/include/new
@@ -92,9 +92,10 @@ void  operator delete[](void* ptr, void*) noexcept;
 #  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>
 #  include <__new/nothrow_t.h>
-#  include <__new/operator_new_delete.h>
+#  include <__new/placement_new_delete.h>
 
 #  if _LIBCPP_STD_VER >= 17
 #    include <__new/interference_size.h>

>From 350282772fd81aa62a553aef5068dc9f7d22b864 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 11 Dec 2024 13:45:09 -0500
Subject: [PATCH 6/6] Format test file

---
 .../ptr.launder/launder.types.verify.cpp      | 22 +++++++++----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.verify.cpp b/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.verify.cpp
index cf93aee7526585..4f2b627b8601a9 100644
--- a/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.verify.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.verify.cpp
@@ -20,17 +20,17 @@
 
 void foo() {}
 
-int main(int, char**)
-{
-    void *p = nullptr;
-    (void) std::launder((               void *) nullptr);
-    (void) std::launder((const          void *) nullptr);
-    (void) std::launder((      volatile void *) nullptr);
-    (void) std::launder((const volatile void *) nullptr);  // expected-error-re@*:* 4 {{static assertion failed{{.*}}can't launder cv-void}}
-    // expected-error@*:* 0-4 {{void pointer argument to '__builtin_launder' is not allowed}}
-
-    (void) std::launder(foo);                              // expected-error-re@*:* 1 {{static assertion failed{{.*}}can't launder functions}}
-    // expected-error@*:* 0-1 {{function pointer argument to '__builtin_launder' is not allowed}}
+int main(int, char**) {
+  void* p = nullptr;
+  (void)std::launder((void*)nullptr);
+  (void)std::launder((const void*)nullptr);
+  (void)std::launder((volatile void*)nullptr);
+  (void)std::launder(
+      (const volatile void*)nullptr); // expected-error-re@*:* 4 {{static assertion failed{{.*}}can't launder cv-void}}
+  // expected-error@*:* 0-4 {{void pointer argument to '__builtin_launder' is not allowed}}
+
+  (void)std::launder(foo); // expected-error-re@*:* 1 {{static assertion failed{{.*}}can't launder functions}}
+  // expected-error@*:* 0-1 {{function pointer argument to '__builtin_launder' is not allowed}}
 
   return 0;
 }



More information about the libcxx-commits mailing list