From 9be819faaf8c1e6882c4ede339f4216d7ea72059 Mon Sep 17 00:00:00 2001 From: Markus Wick Date: Fri, 2 Apr 2021 08:43:26 +0200 Subject: 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. --- src/common/CMakeLists.txt | 1 + src/common/assert.cpp | 11 +++++++++++ src/common/assert.h | 14 ++++++++------ 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 src/common/assert.cpp (limited to 'src') 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 add_library(common STATIC algorithm.h alignment.h + assert.cpp assert.h atomic_ops.h 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 @@ +// Copyright 2021 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "common/assert.h" + +#include "common/common_funcs.h" + +void assert_handle_failure() { + Crash(); +} 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 @@ #pragma once -#include -#include "common/common_funcs.h" #include "common/logging/log.h" +// Sometimes we want to try to continue even after hitting an assert. +// However touching this file yields a global recompilation as this header is included almost +// everywhere. So let's just move the handling of the failed assert to a single cpp file. +void assert_handle_failure(); + // For asserts we'd like to keep all the junk executed when an assert happens away from the // important code in the function. One way of doing this is to put all the relevant code inside a // lambda and force the compiler to not inline it. Unfortunately, MSVC seems to have no syntax to @@ -17,15 +20,14 @@ // enough for our purposes. template #if defined(_MSC_VER) -[[msvc::noinline, noreturn]] +[[msvc::noinline]] #elif defined(__GNUC__) -[[gnu::cold, gnu::noinline, noreturn]] +[[gnu::cold, gnu::noinline]] #endif static void assert_noinline_call(const Fn& fn) { fn(); - Crash(); - exit(1); // Keeps GCC's mouth shut about this actually returning + assert_handle_failure(); } #define ASSERT(_a_) \ -- cgit v1.2.3