Skip to content

Commit 4895ef2

Browse files
committed
[libc++] Simplify when the sized global deallocations overloads are available
1 parent 79dab3f commit 4895ef2

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

libcxx/include/new

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,6 @@ void operator delete[](void* ptr, void*) noexcept;
104104
#endif
105105

106106
#if defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309L
107-
# define _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION 1
108-
#else
109-
# define _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION 0
110-
#endif
111-
112-
#if _LIBCPP_STD_VER >= 14 || _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION
113-
# define _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION 1
114-
#else
115-
# define _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION 0
116-
#endif
117-
118-
#if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION && _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION
119107
# define _LIBCPP_HAS_SIZED_DEALLOCATION 1
120108
#else
121109
# define _LIBCPP_HAS_SIZED_DEALLOCATION 0
@@ -214,7 +202,7 @@ inline constexpr destroying_delete_t destroying_delete{};
214202
_LIBCPP_NOALIAS;
215203
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT;
216204
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
217-
# if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
205+
# if _LIBCPP_HAS_SIZED_DEALLOCATION
218206
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
219207
# endif
220208

@@ -223,7 +211,7 @@ _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz) _
223211
_LIBCPP_NOALIAS;
224212
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT;
225213
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
226-
# if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
214+
# if _LIBCPP_HAS_SIZED_DEALLOCATION
227215
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT;
228216
# endif
229217

@@ -233,7 +221,7 @@ _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz)
233221
operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
234222
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT;
235223
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
236-
# if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
224+
# if _LIBCPP_HAS_SIZED_DEALLOCATION
237225
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
238226
# endif
239227

@@ -243,7 +231,7 @@ operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
243231
operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
244232
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT;
245233
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
246-
# if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
234+
# if _LIBCPP_HAS_SIZED_DEALLOCATION
247235
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
248236
# endif
249237
# endif

libcxxabi/src/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CO
184184
endif()
185185
target_compile_options(cxxabi_shared_objects PRIVATE "${LIBCXXABI_ADDITIONAL_COMPILE_FLAGS}")
186186

187+
# Build with -fsized-deallocation, which is default in recent versions of Clang.
188+
# TODO(LLVM 21): This can be dropped once we only support Clang >= 19.
189+
target_add_compile_flags_if_supported(cxxabi_shared_objcts PRIVATE -fsized-deallocation)
190+
187191
add_library(cxxabi_shared SHARED)
188192
set_target_properties(cxxabi_shared
189193
PROPERTIES
@@ -275,6 +279,10 @@ set_target_properties(cxxabi_static_objects
275279
)
276280
target_compile_options(cxxabi_static_objects PRIVATE "${LIBCXXABI_ADDITIONAL_COMPILE_FLAGS}")
277281

282+
# Build with -fsized-deallocation, which is default in recent versions of Clang.
283+
# TODO(LLVM 21): This can be dropped once we only support Clang >= 19.
284+
target_add_compile_flags_if_supported(cxxabi_static_objcts PRIVATE -fsized-deallocation)
285+
278286
if(LIBCXXABI_HERMETIC_STATIC_LIBRARY)
279287
target_add_compile_flags_if_supported(cxxabi_static_objects PRIVATE -fvisibility=hidden)
280288
# If the hermetic library doesn't define the operator new/delete functions

0 commit comments

Comments
 (0)