Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: use CHECK(false) in switch default case #26502

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3456,7 +3456,7 @@ static ManagedEVPPKey GetPublicOrPrivateKeyFromJs(
is_public = false;
break;
default:
CHECK(!"Invalid key encoding type");
tniessen marked this conversation as resolved.
Show resolved Hide resolved
UNREACHABLE("Invalid key encoding type");
}

if (is_public) {
Expand Down
2 changes: 1 addition & 1 deletion src/node_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ template <typename NativeT,
constexpr NativeT ToNative(uv_timespec_t ts) {
// This template has exactly two specializations below.
static_assert(std::is_arithmetic<NativeT>::value == false, "Not implemented");
UNREACHABLE();
return NativeT();
}

template <>
Expand Down
20 changes: 13 additions & 7 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ void DumpBacktrace(FILE* fp);

#define ABORT() node::Abort()

#define ERROR_AND_ABORT(expr) \
do { \
/* Make sure that this struct does not end up in inline code, but */ \
/* rather in a read-only data section when modifying this code. */ \
static const node::AssertionInfo args = { \
__FILE__ ":" STRINGIFY(__LINE__), #expr, PRETTY_FUNCTION_NAME \
}; \
BridgeAR marked this conversation as resolved.
Show resolved Hide resolved
node::Assert(args); \
} while (0)

#ifdef __GNUC__
#define LIKELY(expr) __builtin_expect(!!(expr), 1)
#define UNLIKELY(expr) __builtin_expect(!!(expr), 0)
Expand All @@ -132,12 +142,7 @@ void DumpBacktrace(FILE* fp);
#define CHECK(expr) \
do { \
if (UNLIKELY(!(expr))) { \
/* Make sure that this struct does not end up in inline code, but */ \
/* rather in a read-only data section when modifying this code. */ \
static const node::AssertionInfo args = { \
__FILE__ ":" STRINGIFY(__LINE__), #expr, PRETTY_FUNCTION_NAME \
}; \
node::Assert(args); \
ERROR_AND_ABORT(expr); \
} \
} while (0)

Expand Down Expand Up @@ -176,7 +181,8 @@ void DumpBacktrace(FILE* fp);
#endif


#define UNREACHABLE() ABORT()
#define UNREACHABLE(expr) \
ERROR_AND_ABORT("Unreachable code reached: " expr)

// TAILQ-style intrusive list node.
template <typename T>
Expand Down