Skip to content

Commit

Permalink
Catch all exceptions in render-test (#5495)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cheneym2 authored Nov 5, 2024
1 parent e22c0b7 commit 4fa76f3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cmake/CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
5 changes: 3 additions & 2 deletions cmake/SlangTarget.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
1 change: 1 addition & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ if(SLANG_ENABLE_TESTS)
EXTRA_COMPILE_DEFINITIONS_PRIVATE
$<$<BOOL:${SLANG_ENABLE_CUDA}>:RENDER_TEST_CUDA>
$<$<BOOL:${SLANG_ENABLE_OPTIX}>:RENDER_TEST_OPTIX>
EXTRA_COMPILE_OPTIONS_PRIVATE /EHa
OUTPUT_NAME render-test-tool
REQUIRED_BY slang-test
FOLDER test/tools
Expand Down

0 comments on commit 4fa76f3

Please sign in to comment.