From 81e299f00ce3df587166ccc94f5997555cce5210 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 20 Feb 2021 16:24:13 +0000 Subject: Mark UNREACHABLE with intrinsics --- src/Globals.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/Globals.h') diff --git a/src/Globals.h b/src/Globals.h index c081c5998..bc868b637 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -35,11 +35,15 @@ // The CRT has a definition for this operator new that stores the debugging info for leak-finding later. #endif + #define UNREACHABLE_INTRINSIC __assume(false) + #elif defined(__GNUC__) // TODO: Can GCC explicitly mark classes as abstract (no instances can be created)? #define abstract + #define UNREACHABLE_INTRINSIC __builtin_unreachable() + #else #error "You are using an unsupported compiler, you might need to #define some stuff here for your compiler" @@ -271,8 +275,12 @@ template class SizeChecker; #endif // else TEST_GLOBALS -/** Use to mark code that should be impossible to reach. */ -#define UNREACHABLE(x) do { FLOGERROR("Hit unreachable code: {0}, file {1}, line {2}", #x, __FILE__, __LINE__); std::abort(); } while (false) +// Use to mark code that should be impossible to reach. +#ifdef NDEBUG + #define UNREACHABLE(x) UNREACHABLE_INTRINSIC +#else + #define UNREACHABLE(x) ( FLOGERROR("Hit unreachable code: {0}, file {1}, line {2}", #x, __FILE__, __LINE__), std::abort(), 0) +#endif -- cgit v1.2.3