From 3d2e3e87f6a861e0aad29b3910467817c0655923 Mon Sep 17 00:00:00 2001 From: Davide Bettio Date: Tue, 25 Jul 2023 00:03:12 +0200 Subject: [PATCH] utils: add UNREACHABLE() macro Instead of directly using GCC builtin __builtin_unreachable() define and use UNREACHABLE() macro. Signed-off-by: Davide Bettio --- src/libAtomVM/nifs.c | 2 +- src/libAtomVM/opcodesswitch.h | 6 +++--- src/libAtomVM/utils.h | 7 +++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/libAtomVM/nifs.c b/src/libAtomVM/nifs.c index e59705765..56efc1abd 100644 --- a/src/libAtomVM/nifs.c +++ b/src/libAtomVM/nifs.c @@ -3465,7 +3465,7 @@ static term open_avm_error_tuple(Context *ctx, enum OpenAVMResult result) reason = globalcontext_make_atom(ctx->global, ATOM_STR("\xD", "not_supported")); break; case AVM_OPEN_OK: - __builtin_unreachable(); + UNREACHABLE(); } if (UNLIKELY(memory_ensure_free(ctx, TUPLE_SIZE(2)) != MEMORY_GC_OK)) { RAISE_ERROR(OUT_OF_MEMORY_ATOM); diff --git a/src/libAtomVM/opcodesswitch.h b/src/libAtomVM/opcodesswitch.h index b190736f9..c1be579c2 100644 --- a/src/libAtomVM/opcodesswitch.h +++ b/src/libAtomVM/opcodesswitch.h @@ -295,7 +295,7 @@ typedef union off += 1 + sz; \ break; \ } \ - default: __builtin_unreachable(); /* help gcc 8.4 */ \ + default: UNREACHABLE(); /* help gcc 8.4 */ \ } \ } @@ -626,7 +626,7 @@ typedef union off += 1 + sz; \ break; \ } \ - default: __builtin_unreachable(); /* help gcc 8.4 */ \ + default: UNREACHABLE(); /* help gcc 8.4 */ \ } \ } @@ -754,7 +754,7 @@ typedef union break; \ } \ case NormalMessage: { \ - __builtin_unreachable(); \ + UNREACHABLE(); \ } \ } \ MailboxMessage *next = signal_message->next; \ diff --git a/src/libAtomVM/utils.h b/src/libAtomVM/utils.h index e4eb6150e..260adccfd 100644 --- a/src/libAtomVM/utils.h +++ b/src/libAtomVM/utils.h @@ -259,4 +259,11 @@ static inline __attribute__((always_inline)) void *cast_func_to_void_ptr(func_pt #define NO_DISCARD(...) #endif +#ifdef __GNUC__ + #define UNREACHABLE() \ + __builtin_unreachable() +#else + #define UNREACHABLE(...) +#endif + #endif