From 738fbf430638f91dfe9fc09f1a53ec92b1bb91fb Mon Sep 17 00:00:00 2001 From: VReaperV Date: Mon, 11 Aug 2025 18:35:52 +0300 Subject: [PATCH 01/11] Implement stacktraces in Sys::Drop()/Error() --- src.cmake | 1 + src/common/StackTrace.h | 109 ++++++++++++++++++++++++++++++++ src/common/System.cpp | 7 +- src/engine/framework/System.cpp | 3 + src/shared/VMMain.cpp | 3 + 5 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 src/common/StackTrace.h diff --git a/src.cmake b/src.cmake index b70f4ca0c3..304b304a8e 100644 --- a/src.cmake +++ b/src.cmake @@ -35,6 +35,7 @@ set(COMMONLIST ${COMMON_DIR}/Optional.h ${COMMON_DIR}/Platform.h ${COMMON_DIR}/Serialize.h + ${COMMON_DIR}/StackTrace.h ${COMMON_DIR}/String.cpp ${COMMON_DIR}/String.h ${COMMON_DIR}/System.cpp diff --git a/src/common/StackTrace.h b/src/common/StackTrace.h new file mode 100644 index 0000000000..fbd391f723 --- /dev/null +++ b/src/common/StackTrace.h @@ -0,0 +1,109 @@ +/* +=========================================================================== + +Daemon BSD Source Code +Copyright (c) 2025 Daemon Developers +All rights reserved. + +This file is part of the Daemon BSD Source Code (Daemon Source Code). + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the Daemon developers nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=========================================================================== +*/ +// StackTrace.h + +#ifndef STACKTRACE_H +#define STACKTRACE_H + +#include "CPPStandard.h" +#include "String.h" + +#include "Log.h" + +#if defined( CPP_STACKTRACE ) + +#include + +inline std::string FormatStackTrace( const std::stacktrace& stackTrace, + const bool skipCurrent = false, const bool compact = false ) { + std::string out; + bool skipped = !skipCurrent; + bool addLineEnd = false; + + for ( const std::stacktrace_entry& entry : stackTrace ) { + if ( !skipped ) { + skipped = true; + continue; + } + + std::string file = entry.source_file(); + +#if defined( _MSC_VER ) + size_t pos = file.find( "src\\n" ); +#else + size_t pos = file.find( "src/" ); +#endif + + if ( pos != std::string::npos ) { + file = file.substr( pos + 4 ); + } + + if ( compact ) { +#if defined( _MSC_VER ) + pos = file.find( "engine\\renderer-vulkan" ); +#else + pos = file.find( "engine/renderer-vulkan" ); +#endif + + if ( pos == std::string::npos ) { + continue; + } + + file = file.substr( pos + 23 ); + } + + if( compact ) { + out += Str::Format( addLineEnd ? "\n%s:%u" : "%s:%u", file, entry.source_line() ); + } else { + out += Str::Format( addLineEnd ? "\n%s:%u: %s" : "%s:%u: %s", file, entry.source_line(), entry.description() ); + } + addLineEnd = true; + } + + return out; +} + +inline void PrintStackTrace( const std::stacktrace& stackTrace = std::stacktrace::current() ) { + Log::Warn( "\n\n====================\nStackTrace:\n%s\n====================\n\n", FormatStackTrace( stackTrace ) ); +} + +#else + +inline void PrintStackTrace() { + Log::Warn( "StackTrace unavailable: CPP23 required" ); +} + +#endif + +#endif // STACKTRACE_H \ No newline at end of file diff --git a/src/common/System.cpp b/src/common/System.cpp index 4da9e244cc..b991e2c523 100644 --- a/src/common/System.cpp +++ b/src/common/System.cpp @@ -51,6 +51,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "qcommon/sys.h" #endif +#include "StackTrace.h" + namespace Sys { // https://devblogs.microsoft.com/oldnewthing/20120105-00/?p=8683 @@ -224,6 +226,8 @@ void Drop(Str::StringRef message) { if (!OnMainThread()) { Sys::Error(message); + } else { + PrintStackTrace(); } // Transform into a fatal error if too many errors are generated in quick @@ -234,8 +238,9 @@ void Drop(Str::StringRef message) if (now - lastError < std::chrono::milliseconds(100)) { if (++errorCount > 3) Sys::Error(message); - } else + } else { errorCount = 0; + } lastError = now; throw DropErr(true, message); diff --git a/src/engine/framework/System.cpp b/src/engine/framework/System.cpp index 80f185a0cf..ec49f9c6d3 100644 --- a/src/engine/framework/System.cpp +++ b/src/engine/framework/System.cpp @@ -37,6 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "System.h" #include "CrashDump.h" #include "CvarSystem.h" +#include "common/StackTrace.h" #include #ifdef _WIN32 #include @@ -556,6 +557,8 @@ void Error(Str::StringRef message) _exit(-1); Log::Warn(message); + PrintStackTrace(); + Shutdown(true, message); OSExit(1); diff --git a/src/shared/VMMain.cpp b/src/shared/VMMain.cpp index e898295e4c..a63574eed2 100644 --- a/src/shared/VMMain.cpp +++ b/src/shared/VMMain.cpp @@ -32,6 +32,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "CommonProxies.h" #include "common/IPC/CommonSyscalls.h" +#include "common/StackTrace.h" + IPC::Channel VM::rootChannel; #ifdef BUILD_VM_NATIVE_EXE @@ -121,6 +123,7 @@ void Sys::Error(Str::StringRef message) } #endif + PrintStackTrace(); SendErrorMsg(message); #ifdef BUILD_VM_IN_PROCESS From d4f7588fff3bd974a50073bcd07ac7925971e65a Mon Sep 17 00:00:00 2001 From: VReaperV Date: Mon, 11 Aug 2025 18:48:34 +0300 Subject: [PATCH 02/11] Add the USE_CPP23 option to CMake --- CMakeLists.txt | 11 +++--- cmake/DaemonFlags.cmake | 78 +++++++++++++++++++++++++++++++++++++++- cmake/DaemonGame.cmake | 6 ++-- src/common/CPPStandard.h | 4 ++- 4 files changed, 90 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 54eaa13555..ecc72235db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -858,7 +858,7 @@ endif() ################################################################################ macro(AddApplicationInternal Target Executable) add_executable(${Target} ${Sources}) - target_link_libraries(${Target} ${A_Target}-objects) + target_link_libraries(${Target} ${A_Target}-objects ${CPP23SupportLibrary}) if (DEPS_DIR) add_dependencies(${Target} runtime_deps) @@ -883,15 +883,16 @@ endmacro() function(AddApplication) set(oneValueArgs Target ExecutableName) - set(multiValueArgs ApplicationMain Definitions Flags Files Libs Tests) + set(multiValueArgs ApplicationMain Definitions Flags CompileFeatures Files Libs Tests) cmake_parse_arguments(A "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) # Reuse object files between the real application and the test one add_library(${A_Target}-objects OBJECT EXCLUDE_FROM_ALL ${A_Files} ${PCH_FILE}) - target_link_libraries(${A_Target}-objects engine-lib ${A_Libs} ${LIBS_BASE}) + target_link_libraries(${A_Target}-objects engine-lib ${A_Libs} ${LIBS_BASE} ${CPP23SupportLibrary}) set_property(TARGET ${A_Target}-objects APPEND PROPERTY COMPILE_OPTIONS ${A_Flags}) set_property(TARGET ${A_Target}-objects APPEND PROPERTY INCLUDE_DIRECTORIES ${ENGINE_DIR} ${MOUNT_DIR} ${LIB_DIR}) set_property(TARGET ${A_Target}-objects APPEND PROPERTY COMPILE_DEFINITIONS ${A_Definitions}) + set_target_properties(${A_Target}-objects PROPERTIES FOLDER "engine/objects") set(Sources WIN32 ${A_ApplicationMain}) @@ -905,7 +906,7 @@ function(AddApplication) # -Wl,--whole-archive -l -Wl,--no-whole-archive set(Sources ${A_ApplicationMain} ${A_Tests}) AddApplicationInternal(test-${A_Target} test-${A_Target}) - target_link_libraries(test-${A_Target} GTest::gmock) + target_link_libraries(test-${A_Target} ${CPP23SupportLibrary} GTest::gmock) endif() ADD_PRECOMPILED_HEADER(${A_Target}-objects) @@ -915,7 +916,7 @@ daemon_write_buildinfo("Engine") if (NOT NACL) add_library(engine-lib EXCLUDE_FROM_ALL ${PCH_FILE} ${BUILDINFOLIST} ${COMMONLIST} ${ENGINELIST}) - target_link_libraries(engine-lib ${LIBS_BASE} ${LIBS_ENGINE_BASE}) + target_link_libraries(engine-lib ${LIBS_BASE} ${LIBS_ENGINE_BASE} ${CPP23SupportLibrary}) set_property(TARGET engine-lib APPEND PROPERTY COMPILE_DEFINITIONS BUILD_ENGINE) set_property(TARGET engine-lib APPEND PROPERTY INCLUDE_DIRECTORIES ${ENGINE_DIR} ${MOUNT_DIR} ${LIB_DIR}) set_property(TARGET engine-lib APPEND PROPERTY COMPILE_OPTIONS ${WARNINGS}) diff --git a/cmake/DaemonFlags.cmake b/cmake/DaemonFlags.cmake index 036c32fbe9..d0c24425c2 100644 --- a/cmake/DaemonFlags.cmake +++ b/cmake/DaemonFlags.cmake @@ -53,6 +53,70 @@ endif() option(USE_RECOMMENDED_CXX_STANDARD "Use recommended C++ standard" ON) mark_as_advanced(USE_RECOMMENDED_CXX_STANDARD) +option(USE_CPP23 "Use C++23 standard where possible" OFF) + +# Required for on Clang/GCC +if(USE_CPP23) + if (DAEMON_CXX_COMPILER_Clang_COMPATIBILITY OR DAEMON_CXX_COMPILER_GCC_COMPATIBILITY) + if ((DAEMON_CXX_COMPILER_Clang_VERSION VERSION_GREATER_EQUAL 19.1.0) OR (DAEMON_CXX_COMPILER_GCC_VERSION VERSION_GREATER_EQUAL 13.3)) + set(CPP23SupportLibraryTryExp TRUE) + endif() + + if ((DAEMON_CXX_COMPILER_Clang_VERSION VERSION_GREATER_EQUAL 17.0.1) OR (DAEMON_CXX_COMPILER_GCC_VERSION VERSION_GREATER_EQUAL 12.1)) + set(CPP23SupportLibraryTryBacktrace TRUE) + endif() + + if (CPP23SupportLibraryTryExp) + set(CPP23SupportLibrary "-lstdc++exp") + set(CPP23SupportLibraryCompatibleCompiler TRUE) + + find_library(HAVE_CPP23SupportLibrary "libstdc++exp") + endif() + + if (CPP23SupportLibraryTryBacktrace AND (HAVE_CPP23SupportLibrary-NOTFOUND OR NOT CPP23SupportLibraryTryExp)) + if (CPP23SupportLibraryCompatibleCompiler) + set(CPP23SupportLibraryOldLibrary TRUE) + endif() + + set(CPP23SupportLibrary "-lstdc++_libbacktrace") + set(CPP23SupportLibraryCompatibleCompiler TRUE) + + find_library(HAVE_CPP23SupportLibrary "libstdc++_libbacktrace") + endif() + + if (HAVE_CPP23SupportLibrary-NOTFOUND) + if (NOT CPP23SupportLibraryCompatibleCompiler) + message(WARNING "Not using : the compiler is too old (requires clang >= 17.0.1 or GCC >= 12.1)") + else() + message(WARNING "Not using : libstdc++exp or libstdc++_backtrace is required, but wasn't found in system paths") + endif() + + set(CPP23SupportLibrary "") + elseif (CXX_FLAGS MATCHES ".*\\-stdlib\\=libc\\+\\+*") + message(WARNING "Not using : only -stdlib=libstdc++ is supported") + + set(CPP23SupportLibrary "") + else() + add_definitions(-DDAEMON_CPP23_SUPPORT_LIBRARY_ENABLED=1) + # FIXME: Doesn't work? + add_compile_options("-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/src=.") + + if (CPP23SupportLibraryOldLibrary) + message(STATUS "Using : found ${CPP23SupportLibrary} (recommended to use libc++exp on this compiler version instead, but it wasn't found)") + else() + message(STATUS "Using : found ${CPP23SupportLibrary}") + endif() + endif() + elseif (MSVC) + # FIXME: Doesn't work in sgame/cgame? + string(REPLACE "/" "\\" backslashed_dir ${CMAKE_CURRENT_SOURCE_DIR}/src) + add_compile_options("/d1trimfile:${backslashed_dir}") + + string(REPLACE "/" "\\" backslashed_dir ${CMAKE_CURRENT_SOURCE_DIR}/daemon/src) + add_compile_options("/d1trimfile:${backslashed_dir}") + endif() +endif() + # Set flag without checking, optional argument specifies build type macro(set_c_flag FLAG) if (${ARGC} GREATER 1) @@ -255,7 +319,19 @@ else() endif() endif() - if (USE_RECOMMENDED_CXX_STANDARD) + if (USE_CPP23) + if (MSVC) + add_compile_options("/std:c++23preview") + else() + try_cxx_flag(GNUXX23 "-std=gnu++23") + + if (NOT FLAG_GNUXX23) + message(WARNING "Requested C++23 is not supported, falling back to C++14") + endif() + endif() + endif() + + if (NOT USE_CPP23 AND (NOT FLAG_GNUXX23 OR USE_RECOMMENDED_CXX_STANDARD)) # PNaCl only defines isascii if __STRICT_ANSI__ is not defined, # always prefer GNU dialect. try_cxx_flag(GNUXX14 "-std=gnu++14") diff --git a/cmake/DaemonGame.cmake b/cmake/DaemonGame.cmake index 33b19b7385..8462617b62 100644 --- a/cmake/DaemonGame.cmake +++ b/cmake/DaemonGame.cmake @@ -135,9 +135,11 @@ function(buildGameModule module_slug) set_target_properties(${module_target} PROPERTIES OUTPUT_NAME "${GAMEMODULE_NAME}" SUFFIX "${PLATFORM_EXE_SUFFIX}") - endif() - target_link_libraries(${module_target} ${GAMEMODULE_LIBS} ${LIBS_BASE}) + target_link_libraries(${module_target} ${GAMEMODULE_LIBS} ${LIBS_BASE}) + else() + target_link_libraries(${module_target} ${GAMEMODULE_LIBS} ${LIBS_BASE} ${CPP23SupportLibrary}) + endif() ADD_PRECOMPILED_HEADER(${module_target}) endfunction() diff --git a/src/common/CPPStandard.h b/src/common/CPPStandard.h index b035a5353d..d657cadd46 100644 --- a/src/common/CPPStandard.h +++ b/src/common/CPPStandard.h @@ -83,7 +83,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define CPP_SOURCE_LOCATION #endif -#if __cpp_lib_stacktrace >= 202011L +/* Clang/GCC support with -lstdc++exp/-lstdlibc++_libbacktrace, but they don't define the feature macro, +so we set a custom macro in build system */ +#if __cpp_lib_stacktrace >= 202011L || defined(DAEMON_CPP23_SUPPORT_LIBRARY_ENABLED) #define CPP_STACKTRACE #endif From ee2103c950abbd88340a007f0906c0431b3a4fa6 Mon Sep 17 00:00:00 2001 From: VReaperV Date: Mon, 11 Aug 2025 19:23:50 +0300 Subject: [PATCH 03/11] Update CI compiler and OS versions --- .appveyor.yml | 12 +++++------- azure-pipelines.yml | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 3c89ff1558..5b29ca6ea2 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -21,12 +21,9 @@ environment: matrix: # see 96d5c1f3ed77b09c64ce7c3c7cbd37c70456b3db # for NMake template - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 - generator: Visual Studio 16 2019 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 + generator: Visual Studio 17 2022 platform: x64 - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 - generator: Visual Studio 16 2019 - platform: win32 build: parallel: true @@ -51,14 +48,15 @@ build_script: :: /Wv pins warnings to a specific compiler version so that new ones :: don't make the build error after Appveyor updates the compiler. - set CFLAGS=/Wv:19.29.30037 + set CFLAGS=/Wv:19.34 - set CXXFLAGS=/Wv:19.29.30037 + set CXXFLAGS=/Wv:19.34 cmake -Wdev -Wdeprecated -G"%generator%" -A"%platform%" -DUSE_PRECOMPILED_HEADER=0 -DUSE_WERROR=1 -DBE_VERBOSE=1 + -DUSE_CPP23=1 -DBUILD_DUMMY_APP=1 -DBUILD_TESTS=1 -S. -Bbuild diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3e2f0ed18a..9152a3adf8 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -67,7 +67,7 @@ jobs: - job: Linux pool: - vmImage: 'ubuntu-22.04' + vmImage: 'ubuntu-24.04' strategy: matrix: GCC: From af6e03cf96d3b386be0ae894cfb83e0f7f47aa49 Mon Sep 17 00:00:00 2001 From: VReaperV Date: Sun, 17 Aug 2025 20:57:47 +0300 Subject: [PATCH 04/11] NUKE sseLoadVec3Unsafe() --- src/engine/qcommon/q_math.cpp | 6 +++--- src/engine/qcommon/q_shared.h | 8 ++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/engine/qcommon/q_math.cpp b/src/engine/qcommon/q_math.cpp index 4de91b1a34..618ec28529 100644 --- a/src/engine/qcommon/q_math.cpp +++ b/src/engine/qcommon/q_math.cpp @@ -744,9 +744,9 @@ void SetPlaneSignbits( cplane_t *out ) int BoxOnPlaneSide( const vec3_t emins, const vec3_t emaxs, const cplane_t *p ) { #if defined(DAEMON_USE_ARCH_INTRINSICS_i686_sse) - auto mins = sseLoadVec3Unsafe( emins ); - auto maxs = sseLoadVec3Unsafe( emaxs ); - auto normal = sseLoadVec3Unsafe( p->normal ); + auto mins = sseLoadVec3( emins ); + auto maxs = sseLoadVec3( emaxs ); + auto normal = sseLoadVec3( p->normal ); auto prod0 = _mm_mul_ps( maxs, normal ); auto prod1 = _mm_mul_ps( mins, normal ); diff --git a/src/engine/qcommon/q_shared.h b/src/engine/qcommon/q_shared.h index 8ade82d371..e83252ee48 100644 --- a/src/engine/qcommon/q_shared.h +++ b/src/engine/qcommon/q_shared.h @@ -1351,10 +1351,6 @@ inline vec_t VectorNormalize2( const vec3_t v, vec3_t out ) v = _mm_loadl_pi( v, (__m64 *)vec ); return v; } - ATTRIBUTE_NO_SANITIZE_ADDRESS inline __m128 sseLoadVec3Unsafe( const vec3_t vec ) { - // Returns garbage in 4th element - return _mm_loadu_ps( vec ); - } inline void sseStoreVec3( __m128 in, vec3_t out ) { _mm_storel_pi( (__m64 *)out, in ); __m128 v = sseSwizzle( in, ZZZZ ); @@ -1368,14 +1364,14 @@ inline vec_t VectorNormalize2( const vec3_t v, vec3_t out ) inline void TransformPoint( const transform_t *t, const vec3_t in, vec3_t out ) { __m128 ts = t->sseTransScale; - __m128 tmp = sseQuatTransform( t->sseRot, sseLoadVec3Unsafe( in ) ); + __m128 tmp = sseQuatTransform( t->sseRot, sseLoadVec3( in ) ); tmp = _mm_mul_ps( tmp, sseSwizzle( ts, WWWW ) ); tmp = _mm_add_ps( tmp, ts ); sseStoreVec3( tmp, out ); } inline void TransformNormalVector( const transform_t *t, const vec3_t in, vec3_t out ) { - __m128 v = sseLoadVec3Unsafe( in ); + __m128 v = sseLoadVec3( in ); v = sseQuatTransform( t->sseRot, v ); sseStoreVec3( v, out ); } From cf785161617039f7d2dc460d9555b2ff390bc923 Mon Sep 17 00:00:00 2001 From: VReaperV Date: Sun, 17 Aug 2025 21:23:32 +0300 Subject: [PATCH 05/11] Suppress broken GCC flag --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ecc72235db..3572894f2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -282,6 +282,7 @@ try_flag(WARNINGS "-W${WARNMODE}old-style-cast") try_flag(WARNINGS "-Woverloaded-virtual") try_flag(WARNINGS "-Wstrict-null-sentinel") try_flag(WARNINGS "-W${WARNMODE}sign-compare") +try_flag(WARNINGS "-Wno-nonnull") # MSVC /wd = warning disable try_flag(WARNINGS "/wd4127") # conditional expression is constant From 4dd32c8fa5d409c122e0b62e72ff200deeb5a8e8 Mon Sep 17 00:00:00 2001 From: slipher Date: Mon, 18 Aug 2025 22:07:48 -0500 Subject: [PATCH 06/11] Fix C++23 flags The MSVC flags were in the GCC section --- cmake/DaemonFlags.cmake | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/cmake/DaemonFlags.cmake b/cmake/DaemonFlags.cmake index d0c24425c2..313906269b 100644 --- a/cmake/DaemonFlags.cmake +++ b/cmake/DaemonFlags.cmake @@ -243,6 +243,13 @@ endif() if (MSVC) set_c_cxx_flag("/MP") + # There is no flag for standards before C++17 + if (USE_CPP23 AND USE_RECOMMENDED_CXX_STANDARD) + set_cxx_flag("/std:c++23preview") + else() + message(FATAL_ERROR "WIENIEONOIENOINIEN") + endif() + if (USE_FAST_MATH) set_c_cxx_flag("/fp:fast") else() @@ -319,26 +326,21 @@ else() endif() endif() - if (USE_CPP23) - if (MSVC) - add_compile_options("/std:c++23preview") - else() + if (USE_RECOMMENDED_CXX_STANDARD) + if (USE_CPP23) try_cxx_flag(GNUXX23 "-std=gnu++23") - if (NOT FLAG_GNUXX23) - message(WARNING "Requested C++23 is not supported, falling back to C++14") + message(FATAL_ERROR "GNU++23 is not supported by the compiler") endif() - endif() - endif() - - if (NOT USE_CPP23 AND (NOT FLAG_GNUXX23 OR USE_RECOMMENDED_CXX_STANDARD)) - # PNaCl only defines isascii if __STRICT_ANSI__ is not defined, - # always prefer GNU dialect. - try_cxx_flag(GNUXX14 "-std=gnu++14") - if (NOT FLAG_GNUXX14) - try_cxx_flag(GNUXX1Y "-std=gnu++1y") - if (NOT FLAG_GNUXX1Y) - message(FATAL_ERROR "GNU++14 is not supported by the compiler") + else() + # PNaCl only defines isascii if __STRICT_ANSI__ is not defined, + # always prefer GNU dialect. + try_cxx_flag(GNUXX14 "-std=gnu++14") + if (NOT FLAG_GNUXX14) + try_cxx_flag(GNUXX1Y "-std=gnu++1y") + if (NOT FLAG_GNUXX1Y) + message(FATAL_ERROR "GNU++14 is not supported by the compiler") + endif() endif() endif() endif() From 5b2f1b566e6156912748a749054502531f8f1fd9 Mon Sep 17 00:00:00 2001 From: slipher Date: Mon, 18 Aug 2025 22:09:39 -0500 Subject: [PATCH 07/11] path stripping flags --- cmake/DaemonFlags.cmake | 27 ++++++++++++++++++--------- src/common/StackTrace.h | 30 ++---------------------------- 2 files changed, 20 insertions(+), 37 deletions(-) diff --git a/cmake/DaemonFlags.cmake b/cmake/DaemonFlags.cmake index 313906269b..9674290590 100644 --- a/cmake/DaemonFlags.cmake +++ b/cmake/DaemonFlags.cmake @@ -98,8 +98,6 @@ if(USE_CPP23) set(CPP23SupportLibrary "") else() add_definitions(-DDAEMON_CPP23_SUPPORT_LIBRARY_ENABLED=1) - # FIXME: Doesn't work? - add_compile_options("-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/src=.") if (CPP23SupportLibraryOldLibrary) message(STATUS "Using : found ${CPP23SupportLibrary} (recommended to use libc++exp on this compiler version instead, but it wasn't found)") @@ -107,13 +105,6 @@ if(USE_CPP23) message(STATUS "Using : found ${CPP23SupportLibrary}") endif() endif() - elseif (MSVC) - # FIXME: Doesn't work in sgame/cgame? - string(REPLACE "/" "\\" backslashed_dir ${CMAKE_CURRENT_SOURCE_DIR}/src) - add_compile_options("/d1trimfile:${backslashed_dir}") - - string(REPLACE "/" "\\" backslashed_dir ${CMAKE_CURRENT_SOURCE_DIR}/daemon/src) - add_compile_options("/d1trimfile:${backslashed_dir}") endif() endif() @@ -226,6 +217,24 @@ macro(try_exe_linker_flag PROP FLAG) endif() endmacro() +# Stripping of absolute paths for __FILE__ / source_location +# Also do without src/ to get libs/ +set(FILENAME_STRIP_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}") +if (NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL DAEMON_DIR) + set(FILENAME_STRIP_DIRS ${FILENAME_STRIP_DIRS} "${DAEMON_DIR}/src" "${DAEMON_DIR}") +endif() +foreach(strip_dir ${FILENAME_STRIP_DIRS}) + if (MSVC) + string(REPLACE "/" "\\" backslashed_dir ${strip_dir}) + # set_c_cxx_flag can't be used because macros barf if the input contains backslashes + # https://gitlab.kitware.com/cmake/cmake/-/issues/19281 + set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "/d1trimfile:${backslashed_dir}") + set(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS} "/d1trimfile:${backslashed_dir}") + else() + try_c_cxx_flag(PREFIX_MAP "-fmacro-prefix-map=${strip_dir}=.") + endif() +endforeach() + if (BE_VERBOSE) set(WARNMODE "no-error=") else() diff --git a/src/common/StackTrace.h b/src/common/StackTrace.h index fbd391f723..818295a0d2 100644 --- a/src/common/StackTrace.h +++ b/src/common/StackTrace.h @@ -57,36 +57,10 @@ inline std::string FormatStackTrace( const std::stacktrace& stackTrace, continue; } - std::string file = entry.source_file(); - -#if defined( _MSC_VER ) - size_t pos = file.find( "src\\n" ); -#else - size_t pos = file.find( "src/" ); -#endif - - if ( pos != std::string::npos ) { - file = file.substr( pos + 4 ); - } - - if ( compact ) { -#if defined( _MSC_VER ) - pos = file.find( "engine\\renderer-vulkan" ); -#else - pos = file.find( "engine/renderer-vulkan" ); -#endif - - if ( pos == std::string::npos ) { - continue; - } - - file = file.substr( pos + 23 ); - } - if( compact ) { - out += Str::Format( addLineEnd ? "\n%s:%u" : "%s:%u", file, entry.source_line() ); + out += Str::Format( addLineEnd ? "\n%s:%u" : "%s:%u", entry.source_file(), entry.source_line()); } else { - out += Str::Format( addLineEnd ? "\n%s:%u: %s" : "%s:%u: %s", file, entry.source_line(), entry.description() ); + out += Str::Format( addLineEnd ? "\n%s:%u: %s" : "%s:%u: %s", entry.source_file(), entry.source_line(), entry.description()); } addLineEnd = true; } From 7441956dd7500250076257596292df6543978aa5 Mon Sep 17 00:00:00 2001 From: VReaperV Date: Wed, 20 Aug 2025 15:14:03 +0300 Subject: [PATCH 08/11] Fix compiler flags -fmacro-prefix-map -> -ffile-prefix-map Fix the compiler flags on MSVC. --- cmake/DaemonFlags.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/DaemonFlags.cmake b/cmake/DaemonFlags.cmake index 9674290590..0e7c340a2b 100644 --- a/cmake/DaemonFlags.cmake +++ b/cmake/DaemonFlags.cmake @@ -228,10 +228,10 @@ foreach(strip_dir ${FILENAME_STRIP_DIRS}) string(REPLACE "/" "\\" backslashed_dir ${strip_dir}) # set_c_cxx_flag can't be used because macros barf if the input contains backslashes # https://gitlab.kitware.com/cmake/cmake/-/issues/19281 - set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "/d1trimfile:${backslashed_dir}") - set(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS} "/d1trimfile:${backslashed_dir}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /d1trimfile:${backslashed_dir}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /d1trimfile:${backslashed_dir}") else() - try_c_cxx_flag(PREFIX_MAP "-fmacro-prefix-map=${strip_dir}=.") + try_c_cxx_flag(PREFIX_MAP "-ffile-prefix-map=${strip_dir}=.") endif() endforeach() From 26e6473c3a7e1285b20134c2b5ad95b978f6fb39 Mon Sep 17 00:00:00 2001 From: VReaperV Date: Wed, 20 Aug 2025 16:39:44 +0300 Subject: [PATCH 09/11] Fix stack overflow with PrintStackTrace() --- src/common/System.cpp | 4 ++-- src/engine/framework/System.cpp | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/common/System.cpp b/src/common/System.cpp index b991e2c523..dbe1c255ee 100644 --- a/src/common/System.cpp +++ b/src/common/System.cpp @@ -226,8 +226,6 @@ void Drop(Str::StringRef message) { if (!OnMainThread()) { Sys::Error(message); - } else { - PrintStackTrace(); } // Transform into a fatal error if too many errors are generated in quick @@ -243,6 +241,8 @@ void Drop(Str::StringRef message) } lastError = now; + PrintStackTrace(); + throw DropErr(true, message); } diff --git a/src/engine/framework/System.cpp b/src/engine/framework/System.cpp index ec49f9c6d3..3b58d98d9c 100644 --- a/src/engine/framework/System.cpp +++ b/src/engine/framework/System.cpp @@ -553,8 +553,9 @@ void Error(Str::StringRef message) { // Crash immediately in case of a recursive error static std::atomic_flag errorEntered; - if (errorEntered.test_and_set()) + if (errorEntered.test_and_set()) { _exit(-1); + } Log::Warn(message); PrintStackTrace(); From c678dd8de82b5a5da5e96213c4d62370840fa43e Mon Sep 17 00:00:00 2001 From: VReaperV Date: Thu, 21 Aug 2025 13:11:34 +0300 Subject: [PATCH 10/11] Make the StackTrace logs less noisy --- cmake/DaemonFlags.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/DaemonFlags.cmake b/cmake/DaemonFlags.cmake index 0e7c340a2b..eadf44e899 100644 --- a/cmake/DaemonFlags.cmake +++ b/cmake/DaemonFlags.cmake @@ -228,10 +228,10 @@ foreach(strip_dir ${FILENAME_STRIP_DIRS}) string(REPLACE "/" "\\" backslashed_dir ${strip_dir}) # set_c_cxx_flag can't be used because macros barf if the input contains backslashes # https://gitlab.kitware.com/cmake/cmake/-/issues/19281 - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /d1trimfile:${backslashed_dir}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /d1trimfile:${backslashed_dir}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /d1trimfile:${backslashed_dir}\\") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /d1trimfile:${backslashed_dir}\\") else() - try_c_cxx_flag(PREFIX_MAP "-ffile-prefix-map=${strip_dir}=.") + try_c_cxx_flag(PREFIX_MAP "-ffile-prefix-map=${strip_dir}/=") endif() endforeach() From 52211194bb111a66c52278739827b60de74ccf58 Mon Sep 17 00:00:00 2001 From: VReaperV Date: Fri, 22 Aug 2025 11:57:49 +0300 Subject: [PATCH 11/11] Clean-up DaemonFlags --- cmake/DaemonFlags.cmake | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmake/DaemonFlags.cmake b/cmake/DaemonFlags.cmake index eadf44e899..1d112d7298 100644 --- a/cmake/DaemonFlags.cmake +++ b/cmake/DaemonFlags.cmake @@ -255,8 +255,6 @@ if (MSVC) # There is no flag for standards before C++17 if (USE_CPP23 AND USE_RECOMMENDED_CXX_STANDARD) set_cxx_flag("/std:c++23preview") - else() - message(FATAL_ERROR "WIENIEONOIENOINIEN") endif() if (USE_FAST_MATH)