From 00ba75ed5ef2132ccbe043b3993bd90e7362966b Mon Sep 17 00:00:00 2001 From: Nitish Sakhawalkar Date: Fri, 8 Mar 2019 12:13:20 -0800 Subject: [PATCH] src: update UNREACHABLE macro to take a string PR-URL: https://github.com/nodejs/node/pull/26502 Reviewed-By: Daniel Bevenius Reviewed-By: Refael Ackermann --- src/node_crypto.cc | 2 +- src/node_file.h | 2 +- src/util.h | 20 +++++++++++++------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index d4399231b9dbc6..dce16b8d4e4006 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -3456,7 +3456,7 @@ static ManagedEVPPKey GetPublicOrPrivateKeyFromJs( is_public = false; break; default: - CHECK(!"Invalid key encoding type"); + UNREACHABLE("Invalid key encoding type"); } if (is_public) { diff --git a/src/node_file.h b/src/node_file.h index b417d4916f8c35..ae50a50b3884b6 100644 --- a/src/node_file.h +++ b/src/node_file.h @@ -162,7 +162,7 @@ template ::value == false, "Not implemented"); - UNREACHABLE(); + return NativeT(); } template <> diff --git a/src/util.h b/src/util.h index 83a7f6c1ef5592..5f02ffd2a3653e 100644 --- a/src/util.h +++ b/src/util.h @@ -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 \ + }; \ + node::Assert(args); \ + } while (0) + #ifdef __GNUC__ #define LIKELY(expr) __builtin_expect(!!(expr), 1) #define UNLIKELY(expr) __builtin_expect(!!(expr), 0) @@ -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) @@ -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