diff --git a/libcxx/include/__config b/libcxx/include/__config --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -868,10 +868,6 @@ # define _LIBCPP_EXPLICIT #endif -#if !__has_builtin(__builtin_operator_new) || !__has_builtin(__builtin_operator_delete) -#define _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE -#endif - #ifdef _LIBCPP_HAS_NO_STRONG_ENUMS # define _LIBCPP_DECLARE_STRONG_ENUM(x) struct _LIBCPP_TYPE_VIS x { enum __lx # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ diff --git a/libcxx/include/new b/libcxx/include/new --- a/libcxx/include/new +++ b/libcxx/include/new @@ -117,11 +117,6 @@ # define _LIBCPP_HAS_NO_SIZED_DEALLOCATION #endif -#if !__has_builtin(__builtin_operator_new) || \ - __has_builtin(__builtin_operator_new) < 201802L -#define _LIBCPP_HAS_NO_BUILTIN_OVERLOADED_OPERATOR_NEW_DELETE -#endif - namespace std // purposefully not using versioning namespace { @@ -234,80 +229,54 @@ #endif } -inline _LIBCPP_INLINE_VISIBILITY -void *__libcpp_allocate(size_t __size, size_t __align) { -#ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION - if (__is_overaligned_for_new(__align)) { - const align_val_t __align_val = static_cast(__align); -# ifdef _LIBCPP_HAS_NO_BUILTIN_OVERLOADED_OPERATOR_NEW_DELETE - return ::operator new(__size, __align_val); -# else - return __builtin_operator_new(__size, __align_val); -# endif - } +template +_LIBCPP_INLINE_VISIBILITY +void* __libcpp_operator_new(_Args ...__args) { +#if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete) + return __builtin_operator_new(__args...); #else - ((void)__align); -#endif -#ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE - return ::operator new(__size); -#else - return __builtin_operator_new(__size); + return ::operator new(__args...); #endif } -struct _DeallocateCaller { - template - static inline void __do_call(void *__ptr, _A1 __a1, _A2 __a2) { -#if defined(_LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE) || \ - defined(_LIBCPP_HAS_NO_BUILTIN_OVERLOADED_OPERATOR_NEW_DELETE) - return ::operator delete(__ptr, __a1, __a2); +template +_LIBCPP_INLINE_VISIBILITY +void __libcpp_operator_delete(_Args ...__args) { +#if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete) + __builtin_operator_delete(__args...); #else - return __builtin_operator_delete(__ptr, __a1, __a2); + ::operator delete(__args...); #endif - } +} - template - static inline void __do_call(void *__ptr, _A1 __a1) { -#if defined(_LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE) || \ - defined(_LIBCPP_HAS_NO_BUILTIN_OVERLOADED_OPERATOR_NEW_DELETE) - return ::operator delete(__ptr, __a1); -#else - return __builtin_operator_delete(__ptr, __a1); -#endif +inline _LIBCPP_INLINE_VISIBILITY +void *__libcpp_allocate(size_t __size, size_t __align) { +#ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION + if (__is_overaligned_for_new(__align)) { + const align_val_t __align_val = static_cast(__align); + return __libcpp_operator_new(__size, __align_val); } - - static inline void __do_call(void *__ptr) { -#ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE - return ::operator delete(__ptr); -#else - return __builtin_operator_delete(__ptr); #endif - } - static inline void __do_deallocate_handle_size(void *__ptr, size_t __size) { -#ifdef _LIBCPP_HAS_NO_SIZED_DEALLOCATION - ((void)__size); - return __do_call(__ptr); -#else - return __do_call(__ptr, __size); -#endif - } + (void)__align; + return __libcpp_operator_new(__size); +} -#ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION - static inline void __do_deallocate_handle_size(void *__ptr, size_t __size, align_val_t __align) { +template +_LIBCPP_INLINE_VISIBILITY +void __do_deallocate_handle_size(void *__ptr, size_t __size, _Args ...__args) { #ifdef _LIBCPP_HAS_NO_SIZED_DEALLOCATION - ((void)__size); - return __do_call(__ptr, __align); + (void)__size; + return __libcpp_operator_delete(__ptr, __args...); #else - return __do_call(__ptr, __size, __align); -#endif - } + return __libcpp_operator_delete(__ptr, __size, __args...); #endif +} - static inline _LIBCPP_INLINE_VISIBILITY - void __do_deallocate_handle_size_align(void *__ptr, size_t __size, size_t __align) { +inline _LIBCPP_INLINE_VISIBILITY +void __libcpp_deallocate(void* __ptr, size_t __size, size_t __align) { #if defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) - ((void)__align); + (void)__align; return __do_deallocate_handle_size(__ptr, __size); #else if (__is_overaligned_for_new(__align)) { @@ -317,31 +286,20 @@ return __do_deallocate_handle_size(__ptr, __size); } #endif - } +} - static inline _LIBCPP_INLINE_VISIBILITY - void __do_deallocate_handle_align(void *__ptr, size_t __align) { +inline _LIBCPP_INLINE_VISIBILITY void __libcpp_deallocate_unsized(void* __ptr, size_t __align) { #if defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) - ((void)__align); - return __do_call(__ptr); + (void)__align; + return __libcpp_operator_delete(__ptr); #else if (__is_overaligned_for_new(__align)) { const align_val_t __align_val = static_cast(__align); - return __do_call(__ptr, __align_val); + return __libcpp_operator_delete(__ptr, __align_val); } else { - return __do_call(__ptr); + return __libcpp_operator_delete(__ptr); } #endif - } -}; - -inline _LIBCPP_INLINE_VISIBILITY -void __libcpp_deallocate(void* __ptr, size_t __size, size_t __align) { - _DeallocateCaller::__do_deallocate_handle_size_align(__ptr, __size, __align); -} - -inline _LIBCPP_INLINE_VISIBILITY void __libcpp_deallocate_unsized(void* __ptr, size_t __align) { - _DeallocateCaller::__do_deallocate_handle_align(__ptr, __align); } template