Skip to content

Commit

Permalink
utils: add UNREACHABLE() macro
Browse files Browse the repository at this point in the history
Instead of directly using GCC builtin __builtin_unreachable() define and use
UNREACHABLE() macro.

Signed-off-by: Davide Bettio <[email protected]>
  • Loading branch information
bettio committed Jul 25, 2023
1 parent 4d0131b commit 6fcc160
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/libAtomVM/nifs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/libAtomVM/opcodesswitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ typedef union
off += 1 + sz; \
break; \
} \
default: __builtin_unreachable(); /* help gcc 8.4 */ \
default: UNREACHABLE(); /* help gcc 8.4 */ \
} \
}

Expand Down Expand Up @@ -626,7 +626,7 @@ typedef union
off += 1 + sz; \
break; \
} \
default: __builtin_unreachable(); /* help gcc 8.4 */ \
default: UNREACHABLE(); /* help gcc 8.4 */ \
} \
}

Expand Down Expand Up @@ -754,7 +754,7 @@ typedef union
break; \
} \
case NormalMessage: { \
__builtin_unreachable(); \
UNREACHABLE(); \
} \
} \
MailboxMessage *next = signal_message->next; \
Expand Down
9 changes: 9 additions & 0 deletions src/libAtomVM/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,13 @@ static inline __attribute__((always_inline)) void *cast_func_to_void_ptr(func_pt
#define NO_DISCARD(...)
#endif

#if defined __has_builtin
#if __has_builtin (__builtin_unreachable)
#define UNREACHABLE() \
__builtin_unreachable()
#endif
#else
#define UNREACHABLE(...)
#endif

#endif

0 comments on commit 6fcc160

Please sign in to comment.