summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-09-26 13:02:00 -0400
committerAndrew Opalach <andrew@akon.city> 2025-09-26 13:02:00 -0400
commit00c292b5bd4f6cf24287c7581d54a60f4b6fdcb7 (patch)
tree09f4a12f5544afc9a45af883c2f8240b01977d84 /include
parent023af72f141005860219b3c63c3a63d2c179b2c1 (diff)
downloadlibalabaster-00c292b5bd4f6cf24287c7581d54a60f4b6fdcb7.tar.gz
libalabaster-00c292b5bd4f6cf24287c7581d54a60f4b6fdcb7.tar.bz2
libalabaster-00c292b5bd4f6cf24287c7581d54a60f4b6fdcb7.zip
macros: Define unreachable()
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'include')
-rw-r--r--include/al/macros.h13
1 files changed, 13 insertions, 0 deletions
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