diff options
author | Liam <byteslice@airmail.cc> | 2022-06-13 00:11:02 +0200 |
---|---|---|
committer | Liam <byteslice@airmail.cc> | 2022-06-14 02:09:32 +0200 |
commit | feaf010fa2c2952eaa6659ea2decaaa2493d4bb8 (patch) | |
tree | 36c28fddb72087b75e06316957275557e166ce71 | |
parent | general: fix compilation on MinGW GCC 12 (diff) | |
download | yuzu-feaf010fa2c2952eaa6659ea2decaaa2493d4bb8.tar yuzu-feaf010fa2c2952eaa6659ea2decaaa2493d4bb8.tar.gz yuzu-feaf010fa2c2952eaa6659ea2decaaa2493d4bb8.tar.bz2 yuzu-feaf010fa2c2952eaa6659ea2decaaa2493d4bb8.tar.lz yuzu-feaf010fa2c2952eaa6659ea2decaaa2493d4bb8.tar.xz yuzu-feaf010fa2c2952eaa6659ea2decaaa2493d4bb8.tar.zst yuzu-feaf010fa2c2952eaa6659ea2decaaa2493d4bb8.zip |
-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 @@ #include "common/settings.h" -void assert_check_condition(bool cond, std::function<void()>&& on_failure) { - if (!cond) [[unlikely]] { - on_failure(); - - if (Settings::values.use_debug_asserts) { - Crash(); - } +void assert_fail_impl() { + if (Settings::values.use_debug_asserts) { + Crash(); } } 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 @@ #pragma once -#include <functional> - #include "common/logging/log.h" // Sometimes we want to try to continue even after hitting an assert. // However touching this file yields a global recompilation as this header is included almost // everywhere. So let's just move the handling of the failed assert to a single cpp file. -// For asserts we'd like to keep all the junk executed when an assert happens away from the -// important code in the function. One way of doing this is to put all the relevant code inside a -// lambda and force the compiler to not inline it. -void assert_check_condition(bool cond, std::function<void()>&& on_failure); - +void assert_fail_impl(); [[noreturn]] void unreachable_impl(); +#ifdef _MSC_VER +#define YUZU_NO_INLINE __declspec(noinline) +#else +#define YUZU_NO_INLINE __attribute__((noinline)) +#endif + #define ASSERT(_a_) \ - do { \ - if (std::is_constant_evaluated()) { \ - if (!(_a_)) { \ - /* Will trigger compile error here */ \ - assert_check_condition(bool(_a_), \ - [] { LOG_CRITICAL(Debug, "Assertion Failed!"); }); \ - } \ - } else { \ - assert_check_condition(bool(_a_), [] { LOG_CRITICAL(Debug, "Assertion Failed!"); }); \ + ([&]() YUZU_NO_INLINE { \ + if (!(_a_)) [[unlikely]] { \ + LOG_CRITICAL(Debug, "Assertion Failed!"); \ + assert_fail_impl(); \ } \ - } while (0) + }()) #define ASSERT_MSG(_a_, ...) \ - do { \ - if (std::is_constant_evaluated()) { \ - if (!(_a_)) { \ - /* Will trigger compile error here */ \ - assert_check_condition(bool(_a_), \ - [] { LOG_CRITICAL(Debug, "Assertion Failed!"); }); \ - } \ - } else { \ - assert_check_condition( \ - bool(_a_), [&] { LOG_CRITICAL(Debug, "Assertion Failed!\n" __VA_ARGS__); }); \ + ([&]() YUZU_NO_INLINE { \ + if (!(_a_)) [[unlikely]] { \ + LOG_CRITICAL(Debug, "Assertion Failed!\n" __VA_ARGS__); \ + assert_fail_impl(); \ } \ - } while (0) + }()) #define UNREACHABLE() \ do { \ |