[glib: 8/13] gtestutils: Call __builtin_undefined() from g_assert_not_reached()



commit 8f2365dc8a3e7135eb662083b9609f9349d101a6
Author: Philip Withnall <withnall endlessm com>
Date:   Tue Mar 5 11:00:12 2019 +0000

    gtestutils: Call __builtin_undefined() from g_assert_not_reached()
    
    Both GCC and Clang treat this as a hint that the code won’t be reached,
    which helps in the cases where they might not have automatically
    detected it already.
    
    It doesn’t change any behaviour of the compiled code, other than
    allowing the compiler to go off into undefined behaviour.
    
    See
    https://gcc.gnu.org/onlinedocs/gcc-8.3.0/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005funreachable.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 glib/gtestutils.h | 7 +++++++
 1 file changed, 7 insertions(+)
---
diff --git a/glib/gtestutils.h b/glib/gtestutils.h
index effc88237..69c6015c5 100644
--- a/glib/gtestutils.h
+++ b/glib/gtestutils.h
@@ -149,7 +149,14 @@ typedef void (*GTestFixtureFunc) (gpointer      fixture,
 #endif
 
 #ifdef G_DISABLE_ASSERT
+/* https://gcc.gnu.org/onlinedocs/gcc-8.3.0/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005funreachable
+ * GCC 5 is not a strict lower bound for versions of GCC which provide __builtin_unreachable(). */
+#if __GNUC__ >= 5 || g_macro__has_builtin(__builtin_unreachable)
+#define g_assert_not_reached()          G_STMT_START { (void) 0; __builtin_unreachable (); } G_STMT_END
+#else  /* if __builtin_unreachable() is not supported: */
 #define g_assert_not_reached()          G_STMT_START { (void) 0; } G_STMT_END
+#endif
+
 #define g_assert(expr)                  G_STMT_START { (void) 0; } G_STMT_END
 #else /* !G_DISABLE_ASSERT */
 #define g_assert_not_reached()          G_STMT_START { g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, 
__LINE__, G_STRFUNC, NULL); } G_STMT_END


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]