summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Markus Wick2021-04-02 08:43:26 +0200
committerGravatar Markus Wick2021-04-04 21:19:33 +0200
commit9be819faaf8c1e6882c4ede339f4216d7ea72059 (patch)
tree1da2c1558e2e86d6defe4bf9b797f1171d847a7a /src
parentMerge pull request #6139 from Morph1984/cmake-fix-build (diff)
downloadyuzu-9be819faaf8c1e6882c4ede339f4216d7ea72059.tar.gz
yuzu-9be819faaf8c1e6882c4ede339f4216d7ea72059.tar.xz
yuzu-9be819faaf8c1e6882c4ede339f4216d7ea72059.zip
common: Move assert failure handling into a cpp file.
Advantage: Altering the handler does not need a full recompilation. Disadvantage: noreturn is droped, so the caller is a bit slower. We quite often run yuzu with a YOLO assertion handler. In fact, only very few games run at all with asserts. This patch allows developers to patch the handler without recompiling everything. The overhead of the missing "noreturn" attribute shoul be negletable.
Diffstat (limited to 'src')
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/assert.cpp11
-rw-r--r--src/common/assert.h14
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
97add_library(common STATIC 97add_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
9void 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.
12void 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.
18template <typename Fn> 21template <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
24static void 27static void
25assert_noinline_call(const Fn& fn) { 28assert_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_) \