diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-11-04 11:53:18 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-11-04 11:59:16 -0500 |
commit | 8eb18cdb65e3fd6111fc50ac5a69d3f7094dd54c (patch) | |
tree | c953d6560def39b85bd685629689fbf219478b7c | |
parent | 80cf88bcb7d3a5a1dc27887d7280e50b1dd89929 (diff) | |
download | bfs-8eb18cdb65e3fd6111fc50ac5a69d3f7094dd54c.tar.xz |
diag: New bfs_unreachable() and bfs_assume() macros
-rw-r--r-- | src/diag.h | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -12,6 +12,7 @@ #include "bfstd.h" #include <stdarg.h> +#include <stddef.h> /** * A source code location. @@ -126,6 +127,37 @@ void bfs_abortf(const struct bfs_loc *loc, const char *format, ...); # define bfs_eassert bfs_everify #endif +/** @internal Wrapper for unreachable(). */ +#ifdef unreachable +# define bfs_unreachable_ unreachable +#elif __has_builtin(__builtin_unreachable) +# define bfs_unreachable_ __builtin_unreachable +#else +_noreturn +static inline void bfs_unreachable_(void) { +} +#endif + +/** + * Abort in debug builds; unreachable in release builds. + */ +#ifdef NDEBUG +# define bfs_unreachable(...) bfs_unreachable_() +#else +# define bfs_unreachable bfs_abort +#endif + +/** + * Assert in debug builds; assume in release builds. + */ +#ifdef NDEBUG +# define bfs_assume(...) bfs_assume_(__VA_ARGS__, ) +# define bfs_assume_(cond, ...) \ + ((cond) ? (void)0 : bfs_unreachable_()) +#else +# define bfs_assume bfs_assert +#endif + struct bfs_ctx; struct bfs_expr; |