diff options
| author | 2021-04-07 13:35:41 -0700 | |
|---|---|---|
| committer | 2021-04-07 13:35:41 -0700 | |
| commit | 3173a53db9f9b97bb45d510467c939ab33eeac1e (patch) | |
| tree | 7c4dfba755429a8cdffd23b7db598662f6c2023d /src/common/assert.h | |
| parent | Merge pull request #6153 from lioncash/svcrange (diff) | |
| parent | common: Move assert failure handling into a cpp file. (diff) | |
| download | yuzu-3173a53db9f9b97bb45d510467c939ab33eeac1e.tar.gz yuzu-3173a53db9f9b97bb45d510467c939ab33eeac1e.tar.xz yuzu-3173a53db9f9b97bb45d510467c939ab33eeac1e.zip | |
Merge pull request #6130 from degasus/better_assert_handling
common: Move assert failure handling into a cpp file.
Diffstat (limited to 'src/common/assert.h')
| -rw-r--r-- | src/common/assert.h | 14 |
1 files changed, 8 insertions, 6 deletions
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_) \ |