mirror of
https://github.com/systemd/systemd.git
synced 2026-08-05 15:40:26 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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__); })
|
||||
|
||||
Reference in New Issue
Block a user