From 00c292b5bd4f6cf24287c7581d54a60f4b6fdcb7 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Fri, 26 Sep 2025 13:02:00 -0400 Subject: macros: Define unreachable() Signed-off-by: Andrew Opalach --- include/al/macros.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/al/macros.h b/include/al/macros.h index 0f116dc..fbf3f7e 100644 --- a/include/al/macros.h +++ b/include/al/macros.h @@ -20,6 +20,19 @@ #define UNLIKELY(x) x #endif +// Keep in mind the idea of an unreachable path is not the same +// as "We should never be here". Unreachable is a compiler hint that means +// "It's logically impossible to be here". +// https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005funreachable +// https://github.com/yehuthi/c_unreachable/blob/1f672a573b2d45cf1479fbb771c17c9ee35bff6b/include/c_unreachable.h#L21C1-L43C7 +#ifndef unreachable +#if defined(__GNUC__) +#define unreachable() (__builtin_unreachable()) +#elif defined(_MSC_VER) +#define unreachable() (__assume(0)) +#endif +#endif + #if defined MIN || defined MAX || defined CLAMP || defined SWAP || defined ARRAY_SIZE || defined STR || defined XSTR || defined BOOLSTR #error "Conflicting definitions for common macros" #endif -- cgit v1.2.3-101-g0448