aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2021-07-14 12:25:11 +0100
committerJonathan Wakely <jwakely@redhat.com>2021-07-15 16:25:42 +0100
commit1f7182d68c24985dace2a94422c671ff987c262c (patch)
tree906ff18cd1947bc0f2d43d269a8257d73f4e460c
parentad5f8ac1d2f2dc92d43663243b52f9e9eb3cf7c0 (diff)
downloadgcc-1f7182d68c24985dace2a94422c671ff987c262c.zip
gcc-1f7182d68c24985dace2a94422c671ff987c262c.tar.gz
gcc-1f7182d68c24985dace2a94422c671ff987c262c.tar.bz2
libstdc++: Add noexcept to __replacement_assert [PR101429]
This results in slightly smaller code when assertions are enabled when either using Clang (because it adds code to call std::terminate when potentially-throwing functions are called in a noexcept function) or a freestanding or non-verbose build (because it doesn't use printf). Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: PR libstdc++/101429 * include/bits/c++config (__replacement_assert): Add noexcept. [!_GLIBCXX_VERBOSE] (__glibcxx_assert_impl): Use __builtin_trap instead of __replacement_assert.
-rw-r--r--libstdc++-v3/include/bits/c++config12
1 files changed, 11 insertions, 1 deletions
diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index 9314117..69ace38 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -500,6 +500,7 @@ namespace std
// Assert.
#if defined(_GLIBCXX_ASSERTIONS) \
|| defined(_GLIBCXX_PARALLEL) || defined(_GLIBCXX_PARALLEL_ASSERTIONS)
+# if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE
namespace std
{
// Avoid the use of assert, because we're trying to keep the <cassert>
@@ -508,6 +509,7 @@ namespace std
inline void
__replacement_assert(const char* __file, int __line,
const char* __function, const char* __condition)
+ _GLIBCXX_NOEXCEPT
{
__builtin_printf("%s:%d: %s: Assertion '%s' failed.\n", __file, __line,
__function, __condition);
@@ -517,10 +519,18 @@ namespace std
#define __glibcxx_assert_impl(_Condition) \
if (__builtin_expect(!bool(_Condition), false)) \
{ \
- __glibcxx_constexpr_assert(_Condition); \
+ __glibcxx_constexpr_assert(false); \
std::__replacement_assert(__FILE__, __LINE__, __PRETTY_FUNCTION__, \
#_Condition); \
}
+# else // ! VERBOSE
+# define __glibcxx_assert_impl(_Condition) \
+ if (__builtin_expect(!bool(_Condition), false)) \
+ { \
+ __glibcxx_constexpr_assert(false); \
+ __builtin_abort(); \
+ }
+#endif
#endif
#if defined(_GLIBCXX_ASSERTIONS)