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
This commit is contained in:
NRK
2023-10-03 21:34:38 +02:00
committed by Daan De Meyer
parent db5d86f5b9
commit be1666886b
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -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