From 8f10fb5065db28760123a21cc8645cf4865d3ff8 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 21 Jan 2019 12:55:52 +0100 Subject: [PATCH] re PR ipa/86590 (Codegen is poor when passing std::string by value with _GLIBCXX_EXTERN_TEMPLATE undefined) PR libstdc++/86590 * include/bits/char_traits.h (__constant_string_p, __constant_char_array_p): Use __builtin_is_constant_evaluated if available. From-SVN: r268112 --- libstdc++-v3/ChangeLog | 7 +++++++ libstdc++-v3/include/bits/char_traits.h | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index cb7f1a61af7..483f1956e49 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2019-01-21 Jakub Jelinek + + PR libstdc++/86590 + * include/bits/char_traits.h (__constant_string_p, + __constant_char_array_p): Use __builtin_is_constant_evaluated if + available. + 2019-01-20 Ulrich Drepper Implement C++20 P0600r1. diff --git a/libstdc++-v3/include/bits/char_traits.h b/libstdc++-v3/include/bits/char_traits.h index 06e04ceaa34..d91fe84063b 100644 --- a/libstdc++-v3/include/bits/char_traits.h +++ b/libstdc++-v3/include/bits/char_traits.h @@ -230,9 +230,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static _GLIBCXX_ALWAYS_INLINE constexpr bool __constant_string_p(const _CharT* __s) { +#ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED + (void) __s; + // In constexpr contexts all strings should be constant. + return __builtin_is_constant_evaluated(); +#else while (__builtin_constant_p(*__s) && *__s) __s++; return __builtin_constant_p(*__s); +#endif } /** @@ -247,10 +253,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static _GLIBCXX_ALWAYS_INLINE constexpr bool __constant_char_array_p(const _CharT* __a, size_t __n) { +#ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED + (void) __a; + (void) __n; + // In constexpr contexts all character arrays should be constant. + return __builtin_is_constant_evaluated(); +#else size_t __i = 0; while (__builtin_constant_p(__a[__i]) && __i < __n) __i++; return __i == __n; +#endif } #endif -- 2.30.2