Skip to content

Commit ef804d8

Browse files
authored
[libc++] Simplify when the sized global deallocations overloads are available (#114667)
There doesn't seem to be much benefit in always providing declarations for the sized deallocations from C++14 onwards if the user explicitly passed `-fno-sized-deallocation` to disable them. This patch simplifies the declarations to be available exactly when the compiler expects sized deallocation functions to be available.
1 parent 3d24c77 commit ef804d8

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

libcxx/include/__new/global_new_delete.h

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,6 @@
2626
#endif
2727

2828
#if defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309L
29-
# define _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION 1
30-
#else
31-
# define _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION 0
32-
#endif
33-
34-
#if _LIBCPP_STD_VER >= 14 || _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION
35-
# define _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION 1
36-
#else
37-
# define _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION 0
38-
#endif
39-
40-
#if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION && _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION
4129
# define _LIBCPP_HAS_SIZED_DEALLOCATION 1
4230
#else
4331
# define _LIBCPP_HAS_SIZED_DEALLOCATION 0
@@ -51,7 +39,7 @@
5139
_LIBCPP_NOALIAS;
5240
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT;
5341
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
54-
# if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
42+
# if _LIBCPP_HAS_SIZED_DEALLOCATION
5543
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
5644
# endif
5745

@@ -60,7 +48,7 @@ _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz) _
6048
_LIBCPP_NOALIAS;
6149
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT;
6250
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
63-
# if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
51+
# if _LIBCPP_HAS_SIZED_DEALLOCATION
6452
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT;
6553
# endif
6654

@@ -70,7 +58,7 @@ _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz)
7058
operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
7159
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT;
7260
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
73-
# if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
61+
# if _LIBCPP_HAS_SIZED_DEALLOCATION
7462
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
7563
# endif
7664

@@ -80,7 +68,7 @@ operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
8068
operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
8169
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT;
8270
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
83-
# if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
71+
# if _LIBCPP_HAS_SIZED_DEALLOCATION
8472
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
8573
# endif
8674
# endif

libcxxabi/src/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ endif()
7777

7878
if (FUCHSIA)
7979
# TODO: Use CMAKE_LINK_LIBRARY_USING_FEATURE once our minimum CMake is at least 3.24
80-
# https://cmake.org/cmake/help/latest/variable/CMAKE_LINK_LIBRARY_USING_FEATURE.html
80+
# https://cmake.org/cmake/help/latest/variable/CMAKE_LINK_LIBRARY_USING_FEATURE.html
8181
add_link_flags("-Wl,--push-state,--as-needed,-lzircon,--pop-state")
8282
endif()
8383

@@ -190,6 +190,10 @@ if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CO
190190
endif()
191191
target_compile_options(cxxabi_shared_objects PRIVATE "${LIBCXXABI_ADDITIONAL_COMPILE_FLAGS}")
192192

193+
# Build with -fsized-deallocation, which is default in recent versions of Clang.
194+
# TODO(LLVM 21): This can be dropped once we only support Clang >= 19.
195+
target_add_compile_flags_if_supported(cxxabi_shared_objects PRIVATE -fsized-deallocation)
196+
193197
add_library(cxxabi_shared SHARED)
194198
set_target_properties(cxxabi_shared
195199
PROPERTIES
@@ -281,6 +285,10 @@ set_target_properties(cxxabi_static_objects
281285
)
282286
target_compile_options(cxxabi_static_objects PRIVATE "${LIBCXXABI_ADDITIONAL_COMPILE_FLAGS}")
283287

288+
# Build with -fsized-deallocation, which is default in recent versions of Clang.
289+
# TODO(LLVM 21): This can be dropped once we only support Clang >= 19.
290+
target_add_compile_flags_if_supported(cxxabi_static_objects PRIVATE -fsized-deallocation)
291+
284292
if(LIBCXXABI_HERMETIC_STATIC_LIBRARY)
285293
target_add_compile_flags_if_supported(cxxabi_static_objects PRIVATE -fvisibility=hidden)
286294
# If the hermetic library doesn't define the operator new/delete functions

0 commit comments

Comments
 (0)