re PR ipa/86590 (Codegen is poor when passing std::string by value with _GLIBCXX_EXTE...
authorJakub Jelinek <jakub@redhat.com>
Mon, 21 Jan 2019 11:55:52 +0000 (12:55 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 21 Jan 2019 11:55:52 +0000 (12:55 +0100)
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
libstdc++-v3/include/bits/char_traits.h

index cb7f1a61af7a59e4ffe24c0874676743e7ddc674..483f1956e49da750e341e4de3898327196bffce0 100644 (file)
@@ -1,3 +1,10 @@
+2019-01-21  Jakub Jelinek  <jakub@redhat.com>
+
+       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  <drepper@redhat.com>
 
        Implement C++20 P0600r1.
index 06e04ceaa34b6f45cf46a465186979d02c3e1bc2..d91fe84063b3cb15821c26b4d0680a98bc6189cc 100644 (file)
@@ -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