From a828ea34394beac017ecac0cda0b2705bdfeb668 Mon Sep 17 00:00:00 2001 From: Nitish Sakhawalkar Date: Fri, 8 Mar 2019 12:13:20 -0800 Subject: [PATCH 1/6] src: update UNREACHABLE macro to take a string --- src/node_crypto.cc | 2 +- src/util.h | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 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/util.h b/src/util.h index 83a7f6c1ef5592..64345aa1b3c829 100644 --- a/src/util.h +++ b/src/util.h @@ -116,6 +116,16 @@ void DumpBacktrace(FILE* fp); #define ABORT() node::Abort() +#define ASSERT(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. */ \ + constexpr 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); \ + ASSERT(expr); \ } \ } while (0) @@ -176,7 +181,7 @@ void DumpBacktrace(FILE* fp); #endif -#define UNREACHABLE() ABORT() +#define UNREACHABLE(expr) ASSERT(expr) // TAILQ-style intrusive list node. template From 7ed7094e83e0944cb3fef1d270a7ef0cde508524 Mon Sep 17 00:00:00 2001 From: Nitish Sakhawalkar Date: Tue, 12 Mar 2019 12:01:58 -0700 Subject: [PATCH 2/6] Address review comment --- src/util.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/util.h b/src/util.h index 64345aa1b3c829..014282de3c59af 100644 --- a/src/util.h +++ b/src/util.h @@ -181,7 +181,8 @@ void DumpBacktrace(FILE* fp); #endif -#define UNREACHABLE(expr) ASSERT(expr) +#define UNREACHABLE(expr) \ + ASSERT("Unreachable code reached:" expr) // TAILQ-style intrusive list node. template From 023e720d6eeeaf4c22f78084983ede26edf80c73 Mon Sep 17 00:00:00 2001 From: Nitish Sakhawalkar Date: Wed, 13 Mar 2019 11:20:19 -0700 Subject: [PATCH 3/6] Rename macro used --- src/util.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util.h b/src/util.h index 014282de3c59af..2e1fafb18a6d60 100644 --- a/src/util.h +++ b/src/util.h @@ -116,7 +116,7 @@ void DumpBacktrace(FILE* fp); #define ABORT() node::Abort() -#define ASSERT(expr) \ +#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. */ \ @@ -142,7 +142,7 @@ void DumpBacktrace(FILE* fp); #define CHECK(expr) \ do { \ if (UNLIKELY(!(expr))) { \ - ASSERT(expr); \ + ERROR_AND_ABORT(expr); \ } \ } while (0) @@ -182,7 +182,7 @@ void DumpBacktrace(FILE* fp); #define UNREACHABLE(expr) \ - ASSERT("Unreachable code reached:" expr) + ERROR_AND_ABORT("Unreachable code reached:" expr) // TAILQ-style intrusive list node. template From f92f8280396dfadfaf58130a508ba1132841bea1 Mon Sep 17 00:00:00 2001 From: Nitish Sakhawalkar Date: Thu, 14 Mar 2019 16:02:47 -0700 Subject: [PATCH 4/6] Update args --- src/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.h b/src/util.h index 2e1fafb18a6d60..f17ad37247d0c9 100644 --- a/src/util.h +++ b/src/util.h @@ -120,7 +120,7 @@ void DumpBacktrace(FILE* fp); 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. */ \ - constexpr node::AssertionInfo args = { \ + const node::AssertionInfo args = { \ __FILE__ ":" STRINGIFY(__LINE__), #expr, PRETTY_FUNCTION_NAME \ }; \ node::Assert(args); \ From a59024bd55960ac750acfbbb786299f1b6d520fb Mon Sep 17 00:00:00 2001 From: Nitish Sakhawalkar Date: Mon, 18 Mar 2019 16:55:19 -0700 Subject: [PATCH 5/6] Update based on comments --- src/node_file.h | 2 +- src/util.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 f17ad37247d0c9..5088a803e3e46e 100644 --- a/src/util.h +++ b/src/util.h @@ -120,7 +120,7 @@ void DumpBacktrace(FILE* fp); 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. */ \ - const node::AssertionInfo args = { \ + static const node::AssertionInfo args = { \ __FILE__ ":" STRINGIFY(__LINE__), #expr, PRETTY_FUNCTION_NAME \ }; \ node::Assert(args); \ From 6d4b6240765ed158e0c8924dc03b7c8b39840dba Mon Sep 17 00:00:00 2001 From: Nitish Sakhawalkar Date: Mon, 18 Mar 2019 17:03:48 -0700 Subject: [PATCH 6/6] Added space after colon in UNREACHABLE macro definition --- src/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.h b/src/util.h index 5088a803e3e46e..5f02ffd2a3653e 100644 --- a/src/util.h +++ b/src/util.h @@ -182,7 +182,7 @@ void DumpBacktrace(FILE* fp); #define UNREACHABLE(expr) \ - ERROR_AND_ABORT("Unreachable code reached:" expr) + ERROR_AND_ABORT("Unreachable code reached: " expr) // TAILQ-style intrusive list node. template