diff options
| -rw-r--r-- | src/common/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/common/assert.cpp | 11 | ||||
| -rw-r--r-- | src/common/assert.h | 14 |
3 files changed, 20 insertions, 6 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 788516ded..66931ac97 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -97,6 +97,7 @@ add_custom_command(OUTPUT scm_rev.cpp | |||
| 97 | add_library(common STATIC | 97 | add_library(common STATIC |
| 98 | algorithm.h | 98 | algorithm.h |
| 99 | alignment.h | 99 | alignment.h |
| 100 | assert.cpp | ||
| 100 | assert.h | 101 | assert.h |
| 101 | atomic_ops.h | 102 | atomic_ops.h |
| 102 | detached_tasks.cpp | 103 | detached_tasks.cpp |
diff --git a/src/common/assert.cpp b/src/common/assert.cpp new file mode 100644 index 000000000..d7d91b96b --- /dev/null +++ b/src/common/assert.cpp | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/assert.h" | ||
| 6 | |||
| 7 | #include "common/common_funcs.h" | ||
| 8 | |||
| 9 | void assert_handle_failure() { | ||
| 10 | Crash(); | ||
| 11 | } | ||
diff --git a/src/common/assert.h b/src/common/assert.h index 06d7b5612..b3ba35c0f 100644 --- a/src/common/assert.h +++ b/src/common/assert.h | |||
| @@ -4,10 +4,13 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <cstdlib> | ||
| 8 | #include "common/common_funcs.h" | ||
| 9 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 10 | 8 | ||
| 9 | // Sometimes we want to try to continue even after hitting an assert. | ||
| 10 | // However touching this file yields a global recompilation as this header is included almost | ||
| 11 | // everywhere. So let's just move the handling of the failed assert to a single cpp file. | ||
| 12 | void assert_handle_failure(); | ||
| 13 | |||
| 11 | // For asserts we'd like to keep all the junk executed when an assert happens away from the | 14 | // For asserts we'd like to keep all the junk executed when an assert happens away from the |
| 12 | // important code in the function. One way of doing this is to put all the relevant code inside a | 15 | // important code in the function. One way of doing this is to put all the relevant code inside a |
| 13 | // lambda and force the compiler to not inline it. Unfortunately, MSVC seems to have no syntax to | 16 | // lambda and force the compiler to not inline it. Unfortunately, MSVC seems to have no syntax to |
| @@ -17,15 +20,14 @@ | |||
| 17 | // enough for our purposes. | 20 | // enough for our purposes. |
| 18 | template <typename Fn> | 21 | template <typename Fn> |
| 19 | #if defined(_MSC_VER) | 22 | #if defined(_MSC_VER) |
| 20 | [[msvc::noinline, noreturn]] | 23 | [[msvc::noinline]] |
| 21 | #elif defined(__GNUC__) | 24 | #elif defined(__GNUC__) |
| 22 | [[gnu::cold, gnu::noinline, noreturn]] | 25 | [[gnu::cold, gnu::noinline]] |
| 23 | #endif | 26 | #endif |
| 24 | static void | 27 | static void |
| 25 | assert_noinline_call(const Fn& fn) { | 28 | assert_noinline_call(const Fn& fn) { |
| 26 | fn(); | 29 | fn(); |
| 27 | Crash(); | 30 | assert_handle_failure(); |
| 28 | exit(1); // Keeps GCC's mouth shut about this actually returning | ||
| 29 | } | 31 | } |
| 30 | 32 | ||
| 31 | #define ASSERT(_a_) \ | 33 | #define ASSERT(_a_) \ |