Update likely/unlikely macros to avoid double negation

I believe this should be identical to the previous code and handle the same
cases (I'm guessing going by the comment that this came from a C codebase
without `bool` types).

The problem with the previous code is that it tripped up the `clangd` analyzer
into thinking `assert()` expressions can/should be simplified via DeMorgan's to
improve readability (because it was seeing the fully expanded macro).
This commit is contained in:
Mahmoud Al-Qudsi 2022-11-29 13:26:32 -06:00
parent 7ee161af8d
commit 063450b8f4

View file

@ -310,8 +310,8 @@ void wcs2string_appending(const wchar_t *in, size_t len, std::string *receiver);
bool should_suppress_stderr_for_tests();
/// Branch prediction hints. Idea borrowed from Linux kernel. Just used for asserts.
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define likely(x) __builtin_expect(bool(x), 1)
#define unlikely(x) __builtin_expect(bool(x), 0)
void assert_is_main_thread(const char *who);
#define ASSERT_IS_MAIN_THREAD_TRAMPOLINE(x) assert_is_main_thread(x)