Skip to content

Commit d21e066

Browse files
nitsakhtargos
authored andcommitted
src: update UNREACHABLE macro to take a string
PR-URL: #26502 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent 206ae31 commit d21e066

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/node_crypto.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3456,7 +3456,7 @@ static ManagedEVPPKey GetPublicOrPrivateKeyFromJs(
34563456
is_public = false;
34573457
break;
34583458
default:
3459-
CHECK(!"Invalid key encoding type");
3459+
UNREACHABLE("Invalid key encoding type");
34603460
}
34613461

34623462
if (is_public) {

src/node_file.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ template <typename NativeT,
162162
constexpr NativeT ToNative(uv_timespec_t ts) {
163163
// This template has exactly two specializations below.
164164
static_assert(std::is_arithmetic<NativeT>::value == false, "Not implemented");
165-
UNREACHABLE();
165+
return NativeT();
166166
}
167167

168168
template <>

src/util.h

+13-7
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ void DumpBacktrace(FILE* fp);
116116

117117
#define ABORT() node::Abort()
118118

119+
#define ERROR_AND_ABORT(expr) \
120+
do { \
121+
/* Make sure that this struct does not end up in inline code, but */ \
122+
/* rather in a read-only data section when modifying this code. */ \
123+
static const node::AssertionInfo args = { \
124+
__FILE__ ":" STRINGIFY(__LINE__), #expr, PRETTY_FUNCTION_NAME \
125+
}; \
126+
node::Assert(args); \
127+
} while (0)
128+
119129
#ifdef __GNUC__
120130
#define LIKELY(expr) __builtin_expect(!!(expr), 1)
121131
#define UNLIKELY(expr) __builtin_expect(!!(expr), 0)
@@ -132,12 +142,7 @@ void DumpBacktrace(FILE* fp);
132142
#define CHECK(expr) \
133143
do { \
134144
if (UNLIKELY(!(expr))) { \
135-
/* Make sure that this struct does not end up in inline code, but */ \
136-
/* rather in a read-only data section when modifying this code. */ \
137-
static const node::AssertionInfo args = { \
138-
__FILE__ ":" STRINGIFY(__LINE__), #expr, PRETTY_FUNCTION_NAME \
139-
}; \
140-
node::Assert(args); \
145+
ERROR_AND_ABORT(expr); \
141146
} \
142147
} while (0)
143148

@@ -176,7 +181,8 @@ void DumpBacktrace(FILE* fp);
176181
#endif
177182

178183

179-
#define UNREACHABLE() ABORT()
184+
#define UNREACHABLE(expr) \
185+
ERROR_AND_ABORT("Unreachable code reached: " expr)
180186

181187
// TAILQ-style intrusive list node.
182188
template <typename T>

0 commit comments

Comments
 (0)