From 3d92d615396d8b3f1c43ad59196e40f15a87bcc8 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Tue, 20 Feb 2024 03:10:25 +0100 Subject: Add the assume() macro --- src/common/macros.h | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src/common') diff --git a/src/common/macros.h b/src/common/macros.h index 6daf08f..3735af6 100644 --- a/src/common/macros.h +++ b/src/common/macros.h @@ -9,19 +9,14 @@ #define streq(x, y) (!strcmp(x, y)) #define u8eq(x, y) (!u8cmp(x, y)) -#if DEBUG || !defined(unreachable) -# if DEBUG -# include "cerr.h" -# ifdef unreachable -# undef unreachable -# endif -# define unreachable() \ - diex("%s:%d: hit unreachable in %s()", __FILE__, __LINE__, __func__) -# elifdef __clang__ -# define unreachable() __builtin_unreachable() -# else -# include -# endif +#if DEBUG +# include "cerr.h" +# define assume(C) \ + ((C) ? (void)0 \ + : diex("%s:%d: %s(): assumption ā€˜%sā€™ failed", __FILE__, __LINE__, \ + __func__, #C)) +#else +# define assume(C) ((C) ? (void)0 : unreachable()) #endif #endif /* !AHOY_COMMON_MACROS_H */ -- cgit v1.2.3