From: NRK Date: Mon, 2 Oct 2023 13:25:00 +0000 (+0600) Subject: macro: use __builtin_unreachable on NDEBUG X-Git-Tag: v255-rc1~347 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be1666886b3f4355ab33f571187e3de8aae3ad40;p=thirdparty%2Fsystemd.git macro: use __builtin_unreachable on NDEBUG note that this slightly changes the semantic of assert when NDEBUG is defined. if there's an extern function call (without attribute pure or similar) then the compiler has to assume it has side effects and still emit the function call. whereas the old assert guaranteed that nothing will be evaluated on NDEBUG. Closes: https://github.com/systemd/systemd/issues/29408 --- diff --git a/src/basic/macro.h b/src/basic/macro.h index 3fb561412a4..0c99d68db26 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -189,7 +189,7 @@ static inline int __coverity_check_and_return__(int condition) { /* We override the glibc assert() here. */ #undef assert #ifdef NDEBUG -#define assert(expr) do {} while (false) +#define assert(expr) ({ if (!(expr)) __builtin_unreachable(); }) #else #define assert(expr) assert_message_se(expr, #expr) #endif diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h index 02412705609..8063f020f83 100644 --- a/src/fundamental/macro-fundamental.h +++ b/src/fundamental/macro-fundamental.h @@ -72,7 +72,7 @@ _noreturn_ void efi_assert(const char *expr, const char *file, unsigned line, const char *function); #ifdef NDEBUG - #define assert(expr) + #define assert(expr) ({ if (!(expr)) __builtin_unreachable(); }) #define assert_not_reached() __builtin_unreachable() #else #define assert(expr) ({ _likely_(expr) ? VOID_0 : efi_assert(#expr, __FILE__, __LINE__, __func__); })