summaryrefslogtreecommitdiffstats
path: root/osdep/compiler.h
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.dev>2021-10-25 10:49:11 +0200
committerNiklas Haas <github-daiK1o@haasn.dev>2021-11-03 14:09:27 +0100
commitc704824b45731f2400355ebe8ae0c576e19dc072 (patch)
treec9410eb47d37fa0b0d5d43af34e6998f3114d1b6 /osdep/compiler.h
parent210767169191e19c70f9c7b63528b0d629ddbcfa (diff)
downloadmpv-c704824b45731f2400355ebe8ae0c576e19dc072.tar.bz2
mpv-c704824b45731f2400355ebe8ae0c576e19dc072.tar.xz
osdep: add MP_UNREACHABLE
This seems to work on gcc, clang and mingw as-is, but I made it conditional on __GNUC__ just in case, even though I can't figure out which compilers we care about that don't export this define. Also replace all instances of assert(0) in the code by MP_UNREACHABLE(), which is a strict improvement.
Diffstat (limited to 'osdep/compiler.h')
-rw-r--r--osdep/compiler.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/osdep/compiler.h b/osdep/compiler.h
index 7c9f859f3a..471fc2ffd1 100644
--- a/osdep/compiler.h
+++ b/osdep/compiler.h
@@ -23,4 +23,10 @@
#define alignof(x) (offsetof(struct {char unalign_; x u;}, u))
#endif
+#ifdef __GNUC__
+#define MP_UNREACHABLE() (assert(!"unreachable"), __builtin_unreachable())
+#else
+#define MP_UNREACHABLE() (assert(!"unreachable"), abort())
+#endif
+
#endif