assert: Check for unreachable code if DYNARMIC_IGNORE_ASSERTS isn't enabled

This commit is contained in:
MerryMage 2021-05-16 21:46:30 +01:00
parent 5bf74b5f04
commit 9de58f2875

View file

@ -24,27 +24,29 @@ template <typename... Ts>
} // namespace Dynarmic::Common
#if defined(NDEBUG)
#if defined(__clang) || defined(__GNUC__)
#define UNREACHABLE() __builtin_unreachable()
#if defined(__clang) || defined(__GNUC__)
#define ASSUME(expr) [&]{ if (!(expr)) __builtin_unreachable(); }()
#elif defined(_MSC_VER)
#define UNREACHABLE() __assume(0)
#elif defined(_MSC_VER)
#define ASSUME(expr) __assume(expr)
#else
#define UNREACHABLE() ASSERT_FALSE("Unreachable code!")
#define ASSUME(expr)
#endif
#else
#define UNREACHABLE() ASSERT_FALSE("Unreachable code!")
#define ASSUME(expr)
#endif
#ifdef DYNARMIC_IGNORE_ASSERTS
#if defined(__clang) || defined(__GNUC__)
#define UNREACHABLE() __builtin_unreachable()
#elif defined(_MSC_VER)
#define UNREACHABLE() __assume(0)
#else
#define UNREACHABLE()
#endif
#define ASSERT(expr) ASSUME(expr)
#define ASSERT_MSG(expr, ...) ASSUME(expr)
#define ASSERT_FALSE(...) UNREACHABLE()
#else
#define UNREACHABLE() ASSERT_FALSE("Unreachable code!")
#define ASSERT(expr) \
[&]{ \
if (UNLIKELY(!(expr))) { \