diff options
| -rw-r--r-- | src/common/assert.cpp | 10 | ||||
| -rw-r--r-- | src/common/assert.h | 45 |
2 files changed, 20 insertions, 35 deletions
diff --git a/src/common/assert.cpp b/src/common/assert.cpp index 1a85faccf..6026b7dc2 100644 --- a/src/common/assert.cpp +++ b/src/common/assert.cpp | |||
| @@ -6,13 +6,9 @@ | |||
| 6 | 6 | ||
| 7 | #include "common/settings.h" | 7 | #include "common/settings.h" |
| 8 | 8 | ||
| 9 | void assert_check_condition(bool cond, std::function<void()>&& on_failure) { | 9 | void assert_fail_impl() { |
| 10 | if (!cond) [[unlikely]] { | 10 | if (Settings::values.use_debug_asserts) { |
| 11 | on_failure(); | 11 | Crash(); |
| 12 | |||
| 13 | if (Settings::values.use_debug_asserts) { | ||
| 14 | Crash(); | ||
| 15 | } | ||
| 16 | } | 12 | } |
| 17 | } | 13 | } |
| 18 | 14 | ||
diff --git a/src/common/assert.h b/src/common/assert.h index fb7808657..8c927fcc0 100644 --- a/src/common/assert.h +++ b/src/common/assert.h | |||
| @@ -4,47 +4,36 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <functional> | ||
| 8 | |||
| 9 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 10 | 8 | ||
| 11 | // Sometimes we want to try to continue even after hitting an assert. | 9 | // Sometimes we want to try to continue even after hitting an assert. |
| 12 | // However touching this file yields a global recompilation as this header is included almost | 10 | // However touching this file yields a global recompilation as this header is included almost |
| 13 | // everywhere. So let's just move the handling of the failed assert to a single cpp file. | 11 | // everywhere. So let's just move the handling of the failed assert to a single cpp file. |
| 14 | 12 | ||
| 15 | // For asserts we'd like to keep all the junk executed when an assert happens away from the | 13 | void assert_fail_impl(); |
| 16 | // important code in the function. One way of doing this is to put all the relevant code inside a | ||
| 17 | // lambda and force the compiler to not inline it. | ||
| 18 | void assert_check_condition(bool cond, std::function<void()>&& on_failure); | ||
| 19 | |||
| 20 | [[noreturn]] void unreachable_impl(); | 14 | [[noreturn]] void unreachable_impl(); |
| 21 | 15 | ||
| 16 | #ifdef _MSC_VER | ||
| 17 | #define YUZU_NO_INLINE __declspec(noinline) | ||
| 18 | #else | ||
| 19 | #define YUZU_NO_INLINE __attribute__((noinline)) | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #define ASSERT(_a_) \ | 22 | #define ASSERT(_a_) \ |
| 23 | do { \ | 23 | ([&]() YUZU_NO_INLINE { \ |
| 24 | if (std::is_constant_evaluated()) { \ | 24 | if (!(_a_)) [[unlikely]] { \ |
| 25 | if (!(_a_)) { \ | 25 | LOG_CRITICAL(Debug, "Assertion Failed!"); \ |
| 26 | /* Will trigger compile error here */ \ | 26 | assert_fail_impl(); \ |
| 27 | assert_check_condition(bool(_a_), \ | ||
| 28 | [] { LOG_CRITICAL(Debug, "Assertion Failed!"); }); \ | ||
| 29 | } \ | ||
| 30 | } else { \ | ||
| 31 | assert_check_condition(bool(_a_), [] { LOG_CRITICAL(Debug, "Assertion Failed!"); }); \ | ||
| 32 | } \ | 27 | } \ |
| 33 | } while (0) | 28 | }()) |
| 34 | 29 | ||
| 35 | #define ASSERT_MSG(_a_, ...) \ | 30 | #define ASSERT_MSG(_a_, ...) \ |
| 36 | do { \ | 31 | ([&]() YUZU_NO_INLINE { \ |
| 37 | if (std::is_constant_evaluated()) { \ | 32 | if (!(_a_)) [[unlikely]] { \ |
| 38 | if (!(_a_)) { \ | 33 | LOG_CRITICAL(Debug, "Assertion Failed!\n" __VA_ARGS__); \ |
| 39 | /* Will trigger compile error here */ \ | 34 | assert_fail_impl(); \ |
| 40 | assert_check_condition(bool(_a_), \ | ||
| 41 | [] { LOG_CRITICAL(Debug, "Assertion Failed!"); }); \ | ||
| 42 | } \ | ||
| 43 | } else { \ | ||
| 44 | assert_check_condition( \ | ||
| 45 | bool(_a_), [&] { LOG_CRITICAL(Debug, "Assertion Failed!\n" __VA_ARGS__); }); \ | ||
| 46 | } \ | 35 | } \ |
| 47 | } while (0) | 36 | }()) |
| 48 | 37 | ||
| 49 | #define UNREACHABLE() \ | 38 | #define UNREACHABLE() \ |
| 50 | do { \ | 39 | do { \ |