]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Use __builtin_expect in __glibcxx_assert
authorJonathan Wakely <jwakely@redhat.com>
Mon, 21 Sep 2020 22:43:25 +0000 (23:43 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 21 Sep 2020 22:43:25 +0000 (23:43 +0100)
libstdc++-v3/ChangeLog:

* include/bits/c++config (__replacement_assert): Add noreturn
attribute.
(__glibcxx_assert_impl): Use __builtin_expect to hint that the
assertion is expected to pass.

libstdc++-v3/include/bits/c++config

index badf9d01a04c336938352295bc3182813a8324be..860bf6dbcb3de8500555c95148f4fc6ad44cf0dd 100644 (file)
@@ -468,7 +468,8 @@ namespace std
 {
   // Avoid the use of assert, because we're trying to keep the <cassert>
   // include out of the mix.
-  extern "C++" inline void
+  extern "C++" _GLIBCXX_NORETURN
+  inline void
   __replacement_assert(const char* __file, int __line,
                       const char* __function, const char* __condition)
   {
@@ -478,7 +479,7 @@ namespace std
   }
 }
 #define __glibcxx_assert_impl(_Condition)                             \
-  if (!bool(_Condition))                                              \
+  if (__builtin_expect(!bool(_Condition), false))                     \
     std::__replacement_assert(__FILE__, __LINE__, __PRETTY_FUNCTION__, \
                              #_Condition)
 #endif