diff --git a/libcxx/include/__config b/libcxx/include/__config --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -575,6 +575,10 @@ #endif // _LIBCPP_COMPILER_[CLANG|GCC|MSVC|IBM] +#ifndef __cpp_constexpr_dynamic_alloc +#define _LIBCPP_HAS_NO_CONSTEXPR_DYNAMIC_ALLOC +#endif + #if defined(_LIBCPP_OBJECT_FORMAT_COFF) #ifdef _DLL @@ -987,6 +991,12 @@ # define _LIBCPP_CONSTEXPR_AFTER_CXX17 #endif +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONSTEXPR_DYNAMIC_ALLOC) +# define _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC constexpr +#else +# define _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC +#endif + // The _LIBCPP_NODISCARD_ATTRIBUTE should only be used to define other // NODISCARD macros to the correct attribute. #if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC) diff --git a/libcxx/include/memory b/libcxx/include/memory --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -1565,47 +1565,47 @@ {typedef allocator_traits::other> other;}; #endif // _LIBCPP_CXX03_LANG - _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static pointer allocate(allocator_type& __a, size_type __n) {return __a.allocate(__n);} - _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint) {return __allocate(__a, __n, __hint, __has_allocate_hint());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT {__a.deallocate(__p, __n);} #ifndef _LIBCPP_HAS_NO_VARIADICS template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args) {__construct(__has_construct(), __a, __p, _VSTD::forward<_Args>(__args)...);} #else // _LIBCPP_HAS_NO_VARIADICS template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static void construct(allocator_type&, _Tp* __p) { ::new ((void*)__p) _Tp(); } template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0) { __construct(__has_construct(), __a, __p, __a0); } template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static void construct(allocator_type&, _Tp* __p, const _A0& __a0, const _A1& __a1) { ::new ((void*)__p) _Tp(__a0, __a1); } template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static void construct(allocator_type&, _Tp* __p, const _A0& __a0, const _A1& __a1, const _A2& __a2) { @@ -1614,15 +1614,15 @@ #endif // _LIBCPP_HAS_NO_VARIADICS template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static void destroy(allocator_type& __a, _Tp* __p) {__destroy(__has_destroy(), __a, __p);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static size_type max_size(const allocator_type& __a) _NOEXCEPT {return __max_size(__has_max_size(), __a);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static allocator_type select_on_container_copy_construction(const allocator_type& __a) {return __select_on_container_copy_construction( @@ -1630,7 +1630,7 @@ __a);} template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static void __construct_forward_with_exception_guarantees(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2) @@ -1648,7 +1648,7 @@ } template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static typename enable_if < @@ -1662,13 +1662,17 @@ ptrdiff_t _Np = __end1 - __begin1; if (_Np > 0) { +#if __has_builtin(__builtin_memcpy) + __builtin_memcpy(__begin2, __begin1, _Np * sizeof(_Tp)); +#else _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp)); +#endif __begin2 += _Np; } } template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static void __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2) @@ -1680,7 +1684,7 @@ template ::type, class _RawDestTp = typename remove_const<_DestTp>::type> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static typename enable_if < @@ -1695,13 +1699,17 @@ ptrdiff_t _Np = __end1 - __begin1; if (_Np > 0) { +#if __has_builtin(__builtin_memcpy) + __builtin_memcpy(const_cast<_RawDestTp*>(__begin2), __begin1, _Np * sizeof(_DestTp)); +#else _VSTD::memcpy(const_cast<_RawDestTp*>(__begin2), __begin1, _Np * sizeof(_DestTp)); +#endif __begin2 += _Np; } } template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static void __construct_backward_with_exception_guarantees(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2) @@ -1722,7 +1730,7 @@ } template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static typename enable_if < @@ -1736,39 +1744,43 @@ ptrdiff_t _Np = __end1 - __begin1; __end2 -= _Np; if (_Np > 0) +#if __has_builtin(__builtin_memcpy) + __builtin_memcpy(__end2, __begin1, _Np * sizeof(_Tp)); +#else _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp)); +#endif } private: - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static pointer __allocate(allocator_type& __a, size_type __n, const_void_pointer __hint, true_type) {return __a.allocate(__n, __hint);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static pointer __allocate(allocator_type& __a, size_type __n, const_void_pointer, false_type) {return __a.allocate(__n);} #ifndef _LIBCPP_HAS_NO_VARIADICS template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args) {__a.construct(__p, _VSTD::forward<_Args>(__args)...);} template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args) { ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...); } #else // _LIBCPP_HAS_NO_VARIADICS template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static void __construct(true_type, allocator_type& __a, _Tp* __p, const _A0& __a0) {__a.construct(__p, __a0);} template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static void __construct(false_type, allocator_type&, _Tp* __p, const _A0& __a0) { @@ -1777,28 +1789,28 @@ #endif // _LIBCPP_HAS_NO_VARIADICS template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static void __destroy(true_type, allocator_type& __a, _Tp* __p) {__a.destroy(__p);} template - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static void __destroy(false_type, allocator_type&, _Tp* __p) { __p->~_Tp(); } - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static size_type __max_size(true_type, const allocator_type& __a) _NOEXCEPT {return __a.max_size();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static size_type __max_size(false_type, const allocator_type&) _NOEXCEPT {return numeric_limits::max() / sizeof(value_type);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static allocator_type __select_on_container_copy_construction(true_type, const allocator_type& __a) {return __a.select_on_container_copy_construction();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY static allocator_type __select_on_container_copy_construction(false_type, const allocator_type& __a) {return __a;} @@ -1844,7 +1856,7 @@ {return _VSTD::addressof(__x);} _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT {return _VSTD::addressof(__x);} - _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator::const_pointer = 0) { if (__n > max_size()) @@ -1852,9 +1864,10 @@ " 'n' exceeds maximum supported size"); return static_cast(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); } - _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) _NOEXCEPT + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY + void deallocate(pointer __p, size_type __n) _NOEXCEPT {_VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));} - _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT + _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT {return size_type(~0) / sizeof(_Tp);} #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) template @@ -1946,6 +1959,7 @@ _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT {return _VSTD::addressof(__x);} + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator::const_pointer = 0) { if (__n > max_size()) @@ -1953,6 +1967,7 @@ " 'n' exceeds maximum supported size"); return static_cast(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); } + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) _NOEXCEPT {_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p), __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT @@ -2022,11 +2037,11 @@ }; template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;} template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;} template diff --git a/libcxx/include/new b/libcxx/include/new --- a/libcxx/include/new +++ b/libcxx/include/new @@ -234,7 +234,8 @@ #endif } -inline _LIBCPP_INLINE_VISIBILITY void *__libcpp_allocate(size_t __size, size_t __align) { +_LIBCPP_CONSTEXPR_DYNAMIC_ALLOC 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); @@ -255,7 +256,7 @@ } struct _DeallocateCaller { - static inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC static inline _LIBCPP_INLINE_VISIBILITY void __do_deallocate_handle_size_align(void *__ptr, size_t __size, size_t __align) { #if defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) ((void)__align); @@ -270,7 +271,7 @@ #endif } - static inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC static inline _LIBCPP_INLINE_VISIBILITY void __do_deallocate_handle_align(void *__ptr, size_t __align) { #if defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) ((void)__align); @@ -286,7 +287,7 @@ } private: - static inline void __do_deallocate_handle_size(void *__ptr, size_t __size) { + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC static inline void __do_deallocate_handle_size(void *__ptr, size_t __size) { #ifdef _LIBCPP_HAS_NO_SIZED_DEALLOCATION ((void)__size); return __do_call(__ptr); @@ -296,7 +297,7 @@ } #ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION - static inline void __do_deallocate_handle_size(void *__ptr, size_t __size, align_val_t __align) { + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC static inline void __do_deallocate_handle_size(void *__ptr, size_t __size, align_val_t __align) { #ifdef _LIBCPP_HAS_NO_SIZED_DEALLOCATION ((void)__size); return __do_call(__ptr, __align); @@ -308,7 +309,7 @@ private: template - static inline void __do_call(void *__ptr, _A1 __a1, _A2 __a2) { + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC 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); @@ -318,7 +319,7 @@ } template - static inline void __do_call(void *__ptr, _A1 __a1) { + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC 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); @@ -327,7 +328,7 @@ #endif } - static inline void __do_call(void *__ptr) { + _LIBCPP_CONSTEXPR_DYNAMIC_ALLOC static inline void __do_call(void *__ptr) { #ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE return ::operator delete(__ptr); #else @@ -336,11 +337,13 @@ } }; -inline _LIBCPP_INLINE_VISIBILITY void __libcpp_deallocate(void* __ptr, size_t __size, size_t __align) { +_LIBCPP_CONSTEXPR_DYNAMIC_ALLOC 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) { +_LIBCPP_CONSTEXPR_DYNAMIC_ALLOC inline _LIBCPP_INLINE_VISIBILITY +void __libcpp_deallocate_unsized(void* __ptr, size_t __align) { _DeallocateCaller::__do_deallocate_handle_align(__ptr, __align); } diff --git a/libcxx/include/version b/libcxx/include/version --- a/libcxx/include/version +++ b/libcxx/include/version @@ -218,6 +218,9 @@ # define __cpp_lib_char8_t 201811L # endif // # define __cpp_lib_concepts 201806L +# if !defined(_LIBCPP_HAS_NO_CONSTEXPR_DYNAMIC_ALLOC) +# define __cpp_lib_constexpr_dynamic_alloc 201907L +# endif // # define __cpp_lib_constexpr_misc 201811L // # define __cpp_lib_constexpr_swap_algorithms 201806L # if _LIBCPP_STD_VER > 17 && defined(__cpp_impl_destroying_delete) && __cpp_impl_destroying_delete >= 201806L