Use the new __has_feature(cxx_constexpr_string_builtins) for detection of the C-string intrinsics for constexpr support in std::char_traits. Thanks to Richard for the intrisic support.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@293154 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2017-01-26 06:58:29 +00:00
parent 19cd3fd00f
commit f783971aa0
2 changed files with 7 additions and 14 deletions

View File

@@ -411,15 +411,6 @@ namespace std {
#define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) #define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
#endif #endif
// A constexpr version of __builtin_memcmp was added in clang 4.0
#if __has_builtin(__builtin_memcmp)
# ifdef __apple_build_version__
// No shipping version of Apple's clang has constexpr __builtin_memcmp
# elif __clang_major__ > 3
# define _LIBCPP_BUILTIN_MEMCMP_ISCONSTEXPR
# endif
#endif
#elif defined(_LIBCPP_COMPILER_GCC) #elif defined(_LIBCPP_COMPILER_GCC)
#define _ALIGNAS(x) __attribute__((__aligned__(x))) #define _ALIGNAS(x) __attribute__((__aligned__(x)))

View File

@@ -243,7 +243,7 @@ char_traits<char>::compare(const char_type* __s1, const char_type* __s2, size_t
{ {
if (__n == 0) if (__n == 0)
return 0; return 0;
#ifdef _LIBCPP_BUILTIN_MEMCMP_ISCONSTEXPR #if __has_feature(cxx_constexpr_string_builtins)
return __builtin_memcmp(__s1, __s2, __n); return __builtin_memcmp(__s1, __s2, __n);
#elif _LIBCPP_STD_VER <= 14 #elif _LIBCPP_STD_VER <= 14
return memcmp(__s1, __s2, __n); return memcmp(__s1, __s2, __n);
@@ -265,7 +265,9 @@ char_traits<char>::find(const char_type* __s, size_t __n, const char_type& __a)
{ {
if (__n == 0) if (__n == 0)
return NULL; return NULL;
#if _LIBCPP_STD_VER <= 14 #if __has_feature(cxx_constexpr_string_builtins)
return __builtin_char_memchr(__s, to_int_type(__a), __n);
#elif _LIBCPP_STD_VER <= 14
return (const char_type*) memchr(__s, to_int_type(__a), __n); return (const char_type*) memchr(__s, to_int_type(__a), __n);
#else #else
for (; __n; --__n) for (; __n; --__n)
@@ -331,7 +333,7 @@ char_traits<wchar_t>::compare(const char_type* __s1, const char_type* __s2, size
{ {
if (__n == 0) if (__n == 0)
return 0; return 0;
#if __has_builtin(__builtin_wmemcmp) #if __has_feature(cxx_constexpr_string_builtins)
return __builtin_wmemcmp(__s1, __s2, __n); return __builtin_wmemcmp(__s1, __s2, __n);
#elif _LIBCPP_STD_VER <= 14 #elif _LIBCPP_STD_VER <= 14
return wmemcmp(__s1, __s2, __n); return wmemcmp(__s1, __s2, __n);
@@ -351,7 +353,7 @@ inline _LIBCPP_CONSTEXPR_AFTER_CXX14
size_t size_t
char_traits<wchar_t>::length(const char_type* __s) _NOEXCEPT char_traits<wchar_t>::length(const char_type* __s) _NOEXCEPT
{ {
#if __has_builtin(__builtin_wcslen) #if __has_feature(cxx_constexpr_string_builtins)
return __builtin_wcslen(__s); return __builtin_wcslen(__s);
#elif _LIBCPP_STD_VER <= 14 #elif _LIBCPP_STD_VER <= 14
return wcslen(__s); return wcslen(__s);
@@ -369,7 +371,7 @@ char_traits<wchar_t>::find(const char_type* __s, size_t __n, const char_type& __
{ {
if (__n == 0) if (__n == 0)
return NULL; return NULL;
#if __has_builtin(__builtin_wmemchr) #if __has_feature(cxx_constexpr_string_builtins)
return __builtin_wmemchr(__s, __a, __n); return __builtin_wmemchr(__s, __a, __n);
#elif _LIBCPP_STD_VER <= 14 #elif _LIBCPP_STD_VER <= 14
return wmemchr(__s, __a, __n); return wmemchr(__s, __a, __n);