diff options
Diffstat (limited to 'src/common/assert.h')
| -rw-r--r-- | src/common/assert.h | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/common/assert.h b/src/common/assert.h index cd9b819a9..04e80c87a 100644 --- a/src/common/assert.h +++ b/src/common/assert.h | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <cstdlib> | 7 | #include <cstdlib> |
| 8 | |||
| 9 | #include "common/common_funcs.h" | 8 | #include "common/common_funcs.h" |
| 10 | #include "common/logging/log.h" | 9 | #include "common/logging/log.h" |
| 11 | 10 | ||
| @@ -18,25 +17,29 @@ | |||
| 18 | // enough for our purposes. | 17 | // enough for our purposes. |
| 19 | template <typename Fn> | 18 | template <typename Fn> |
| 20 | #if defined(_MSC_VER) | 19 | #if defined(_MSC_VER) |
| 21 | __declspec(noinline, noreturn) | 20 | __declspec(noinline, noreturn) |
| 22 | #elif defined(__GNUC__) | 21 | #elif defined(__GNUC__) |
| 23 | __attribute__((noinline, noreturn, cold)) | 22 | __attribute__((noinline, noreturn, cold)) |
| 24 | #endif | 23 | #endif |
| 25 | static void assert_noinline_call(const Fn& fn) { | 24 | static void assert_noinline_call(const Fn& fn) { |
| 26 | fn(); | 25 | fn(); |
| 27 | Crash(); | 26 | Crash(); |
| 28 | exit(1); // Keeps GCC's mouth shut about this actually returning | 27 | exit(1); // Keeps GCC's mouth shut about this actually returning |
| 29 | } | 28 | } |
| 30 | 29 | ||
| 31 | #define ASSERT(_a_) \ | 30 | #define ASSERT(_a_) \ |
| 32 | do if (!(_a_)) { assert_noinline_call([] { \ | 31 | do \ |
| 33 | LOG_CRITICAL(Debug, "Assertion Failed!"); \ | 32 | if (!(_a_)) { \ |
| 34 | }); } while (0) | 33 | assert_noinline_call([] { LOG_CRITICAL(Debug, "Assertion Failed!"); }); \ |
| 34 | } \ | ||
| 35 | while (0) | ||
| 35 | 36 | ||
| 36 | #define ASSERT_MSG(_a_, ...) \ | 37 | #define ASSERT_MSG(_a_, ...) \ |
| 37 | do if (!(_a_)) { assert_noinline_call([&] { \ | 38 | do \ |
| 38 | LOG_CRITICAL(Debug, "Assertion Failed!\n" __VA_ARGS__); \ | 39 | if (!(_a_)) { \ |
| 39 | }); } while (0) | 40 | assert_noinline_call([&] { LOG_CRITICAL(Debug, "Assertion Failed!\n" __VA_ARGS__); }); \ |
| 41 | } \ | ||
| 42 | while (0) | ||
| 40 | 43 | ||
| 41 | #define UNREACHABLE() ASSERT_MSG(false, "Unreachable code!") | 44 | #define UNREACHABLE() ASSERT_MSG(false, "Unreachable code!") |
| 42 | #define UNREACHABLE_MSG(...) ASSERT_MSG(false, __VA_ARGS__) | 45 | #define UNREACHABLE_MSG(...) ASSERT_MSG(false, __VA_ARGS__) |
| @@ -50,4 +53,4 @@ static void assert_noinline_call(const Fn& fn) { | |||
| 50 | #endif | 53 | #endif |
| 51 | 54 | ||
| 52 | #define UNIMPLEMENTED() DEBUG_ASSERT_MSG(false, "Unimplemented code!") | 55 | #define UNIMPLEMENTED() DEBUG_ASSERT_MSG(false, "Unimplemented code!") |
| 53 | #define UNIMPLEMENTED_MSG(_a_, ...) ASSERT_MSG(false, _a_, __VA_ARGS__) \ No newline at end of file | 56 | #define UNIMPLEMENTED_MSG(_a_, ...) ASSERT_MSG(false, _a_, __VA_ARGS__) |