Skip to content

Commit

Permalink
Merge pull request #700 from bettio/unreachable-macro
Browse files Browse the repository at this point in the history
utils: add UNREACHABLE() macro

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
  • Loading branch information
bettio committed Jul 25, 2023
2 parents 4d0131b + 3d2e3e8 commit cca89fa
Show file tree
Hide file tree
Showing 3 changed files with 11 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
7 changes: 7 additions & 0 deletions src/libAtomVM/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cca89fa

Please sign in to comment.