From 1c8f0b8909f342201f84def1efb8c6fb4386cc2c Mon Sep 17 00:00:00 2001 From: Alex Rønne Petersen Date: Fri, 23 Aug 2024 02:59:46 +0200 Subject: libcxx: Update to LLVM 19. * Moved the tz.cpp patch to experimental/tzdb.cpp. * Extended the __config_site patch to a few more files. --- .../include/__string/constexpr_c_functions.h | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'lib/libcxx/include/__string/constexpr_c_functions.h') diff --git a/lib/libcxx/include/__string/constexpr_c_functions.h b/lib/libcxx/include/__string/constexpr_c_functions.h index 198f0f5e68..a978f816f1 100644 --- a/lib/libcxx/include/__string/constexpr_c_functions.h +++ b/lib/libcxx/include/__string/constexpr_c_functions.h @@ -35,18 +35,33 @@ _LIBCPP_BEGIN_NAMESPACE_STD // of elements as opposed to a number of bytes. enum class __element_count : size_t {}; -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 size_t __constexpr_strlen(const char* __str) { +template +inline const bool __is_char_type = false; + +template <> +inline const bool __is_char_type = true; + +#ifndef _LIBCPP_HAS_NO_CHAR8_T +template <> +inline const bool __is_char_type = true; +#endif + +template +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 size_t __constexpr_strlen(const _Tp* __str) _NOEXCEPT { + static_assert(__is_char_type<_Tp>, "__constexpr_strlen only works with char and char8_t"); // GCC currently doesn't support __builtin_strlen for heap-allocated memory during constant evaluation. // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70816 -#ifdef _LIBCPP_COMPILER_GCC if (__libcpp_is_constant_evaluated()) { +#if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_COMPILER_CLANG_BASED) + if constexpr (is_same_v<_Tp, char>) + return __builtin_strlen(__str); +#endif size_t __i = 0; for (; __str[__i] != '\0'; ++__i) ; return __i; } -#endif - return __builtin_strlen(__str); + return __builtin_strlen(reinterpret_cast(__str)); } // Because of __libcpp_is_trivially_lexicographically_comparable we know that comparing the object representations is @@ -108,7 +123,7 @@ __constexpr_memcmp_equal(const _Tp* __lhs, const _Up* __rhs, __element_count __n } return true; } else { - return __builtin_memcmp(__lhs, __rhs, __count * sizeof(_Tp)) == 0; + return ::__builtin_memcmp(__lhs, __rhs, __count * sizeof(_Tp)) == 0; } } @@ -209,7 +224,7 @@ __constexpr_memmove(_Tp* __dest, _Up* __src, __element_count __n) { std::__assign_trivially_copyable(__dest[__i], __src[__i]); } } else if (__count > 0) { - ::__builtin_memmove(__dest, __src, (__count - 1) * sizeof(_Tp) + __libcpp_datasizeof<_Tp>::value); + ::__builtin_memmove(__dest, __src, (__count - 1) * sizeof(_Tp) + __datasizeof_v<_Tp>); } return __dest; } -- cgit v1.2.3