This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Transform assertion into optimization hints
- From: François Dumont <frs dot dumont at gmail dot com>
- To: "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 17 Sep 2018 22:38:25 +0200
- Subject: Transform assertion into optimization hints
We talk about it a while back.
I've run testsuite several times since I have this patch on my local
copy. Note that when I implemented it the wrong way tests started to
fail so it is clearly having an effect on the generated code.
* include/bits/c++config [__OPTIMIZE__](__glibcxx_assert): Define as
optimization hint
using __builtin_unreachable.
Ok to commit ?
François
diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index d499d32b51e..24bdc97e0f5 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -466,6 +466,9 @@ namespace std
#if defined(_GLIBCXX_ASSERTIONS)
# define __glibcxx_assert(_Condition) __glibcxx_assert_impl(_Condition)
+#elif defined(__OPTIMIZE__)
+# define __glibcxx_assert(_Condition) \
+ do { if (! (_Condition)) __builtin_unreachable(); } while (false)
#else
# define __glibcxx_assert(_Condition)
#endif