From 4fa76f374c0c35c9c7d186e8addf6861e98baaec Mon Sep 17 00:00:00 2001 From: cheneym2 Date: Tue, 5 Nov 2024 17:28:36 -0500 Subject: [PATCH] Catch all exceptions in render-test (#5495) Catch all exceptions in render-test In MSVC, the /EHsc flag is used by default, it causes only C++ (synchronous) exceptions to be caught by try/catch blocks. The /EHa flag can instead be used to catch both synchronous C++ exceptions as well as structured asynchronous exceptions such as those seen in segfaults or other typical bugs. Using /EHa allows render-test to not crash completely if there is a buggy graphics driver in the system. Issue 5275 --- cmake/CompilerFlags.cmake | 4 ++++ cmake/SlangTarget.cmake | 5 +++-- tools/CMakeLists.txt | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cmake/CompilerFlags.cmake b/cmake/CompilerFlags.cmake index cd9021cd03..5558c346b4 100644 --- a/cmake/CompilerFlags.cmake +++ b/cmake/CompilerFlags.cmake @@ -16,6 +16,10 @@ function(add_supported_cxx_flags target) endif() foreach(flag ${flags}) + # /EHa enables SEH on Windows, it is not available in Linux. + if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + string(REGEX REPLACE "/EHa" "" flag "${flag}") + endif() # remove the `no-` prefix from warnings because gcc doesn't treat it as an # error on its own string(REGEX REPLACE "\\-Wno\\-(.+)" "-W\\1" flag_to_test "${flag}") diff --git a/cmake/SlangTarget.cmake b/cmake/SlangTarget.cmake index 4a3b757046..98517a1bae 100644 --- a/cmake/SlangTarget.cmake +++ b/cmake/SlangTarget.cmake @@ -337,9 +337,10 @@ function(slang_add_target dir type) ) endif() if(ARG_EXTRA_COMPILE_OPTIONS_PRIVATE) - target_compile_options( + add_supported_cxx_flags( ${target} - PRIVATE ${ARG_EXTRA_COMPILE_OPTIONS_PRIVATE} + PRIVATE + ${ARG_EXTRA_COMPILE_OPTIONS_PRIVATE} ) endif() diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 9af17b349d..ef4d175562 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -276,6 +276,7 @@ if(SLANG_ENABLE_TESTS) EXTRA_COMPILE_DEFINITIONS_PRIVATE $<$:RENDER_TEST_CUDA> $<$:RENDER_TEST_OPTIX> + EXTRA_COMPILE_OPTIONS_PRIVATE /EHa OUTPUT_NAME render-test-tool REQUIRED_BY slang-test FOLDER test/tools