Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libAtomVM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ add_library(libAtomVM ${SOURCE_FILES} ${HEADER_FILES})
target_include_directories(libAtomVM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_features(libAtomVM PUBLIC c_std_11)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(libAtomVM PUBLIC -Wall ${MAYBE_PEDANTIC_FLAG} ${MAYBE_WERROR_FLAG} -Wextra -ggdb -Werror=incompatible-pointer-types)
target_compile_options(libAtomVM PUBLIC -Wall ${MAYBE_PEDANTIC_FLAG} ${MAYBE_WERROR_FLAG} -Wextra -ggdb -Werror=incompatible-pointer-types -Wswitch-enum)
elseif (CMAKE_C_COMPILER_ID MATCHES "Clang")
target_compile_options(libAtomVM PUBLIC -Wall ${MAYBE_PEDANTIC_FLAG} -Wno-gnu-zero-variadic-macro-arguments --extra-warnings -Werror=incompatible-pointer-types ${MAYBE_WERROR_FLAG} -g)
target_compile_options(libAtomVM PUBLIC -Wall ${MAYBE_PEDANTIC_FLAG} -Wno-gnu-zero-variadic-macro-arguments --extra-warnings -Werror=incompatible-pointer-types -Wswitch-enum ${MAYBE_WERROR_FLAG} -g)
endif()

if (ENABLE_REALLOC_GC)
Expand Down
5 changes: 5 additions & 0 deletions src/libAtomVM/term.c
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,11 @@ TermCompareResult term_compare(term t, term other, TermCompareOpts opts, GlobalC
break;
}
}
case TERM_TYPE_INDEX_NIL:
// This cannot happen, since this branch is executed only when
// `type_t == type_other`,
// but we do `t == other` as the first thing, making this case unreachable.
case TERM_TYPE_INDEX_INVALID:
default:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default: UNREACHABLE(); tells the compiler that any other value is undefined behavior, so it can perform additional optimizations. Otherwise it stills emit code for handling values outside the cases we defined.
Variables having an enum type are glorified integers, so the compiler by default doesn't infer that only allowed values are the enum values.

UNREACHABLE();
}
Expand Down
Loading