summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/assert.cpp5
-rw-r--r--src/common/assert.h14
-rw-r--r--src/common/settings.cpp2
3 files changed, 18 insertions, 3 deletions
diff --git a/src/common/assert.cpp b/src/common/assert.cpp
index b44570528..a27a025ae 100644
--- a/src/common/assert.cpp
+++ b/src/common/assert.cpp
@@ -11,3 +11,8 @@ void assert_handle_failure() {
11 Crash(); 11 Crash();
12 } 12 }
13} 13}
14
15[[noreturn]] void unreachable_impl() {
16 Crash();
17 throw std::runtime_error("Unreachable code");
18}
diff --git a/src/common/assert.h b/src/common/assert.h
index dbfd8abaf..478bfa856 100644
--- a/src/common/assert.h
+++ b/src/common/assert.h
@@ -11,6 +11,8 @@
11// 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.
12void assert_handle_failure(); 12void assert_handle_failure();
13 13
14[[noreturn]] void unreachable_impl();
15
14// For asserts we'd like to keep all the junk executed when an assert happens away from the 16// For asserts we'd like to keep all the junk executed when an assert happens away from the
15// important code in the function. One way of doing this is to put all the relevant code inside a 17// important code in the function. One way of doing this is to put all the relevant code inside a
16// lambda and force the compiler to not inline it. Unfortunately, MSVC seems to have no syntax to 18// lambda and force the compiler to not inline it. Unfortunately, MSVC seems to have no syntax to
@@ -44,9 +46,17 @@ assert_noinline_call(const Fn& fn) {
44 } \ 46 } \
45 while (0) 47 while (0)
46 48
47#define UNREACHABLE() assert_noinline_call([] { LOG_CRITICAL(Debug, "Unreachable code!"); }) 49#define UNREACHABLE() \
50 do { \
51 assert_noinline_call([] { LOG_CRITICAL(Debug, "Unreachable code!"); }); \
52 unreachable_impl(); \
53 } while (0)
54
48#define UNREACHABLE_MSG(...) \ 55#define UNREACHABLE_MSG(...) \
49 assert_noinline_call([&] { LOG_CRITICAL(Debug, "Unreachable code!\n" __VA_ARGS__); }) 56 do { \
57 assert_noinline_call([&] { LOG_CRITICAL(Debug, "Unreachable code!\n" __VA_ARGS__); }); \
58 unreachable_impl(); \
59 } while (0)
50 60
51#ifdef _DEBUG 61#ifdef _DEBUG
52#define DEBUG_ASSERT(_a_) ASSERT(_a_) 62#define DEBUG_ASSERT(_a_) ASSERT(_a_)
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index 6ffab63af..751549583 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -147,7 +147,7 @@ void UpdateRescalingInfo() {
147 info.down_shift = 0; 147 info.down_shift = 0;
148 break; 148 break;
149 default: 149 default:
150 UNREACHABLE(); 150 ASSERT(false);
151 info.up_scale = 1; 151 info.up_scale = 1;
152 info.down_shift = 0; 152 info.down_shift = 0;
153 } 153 }