Skip to content

Commit 4fa76f3

Browse files
authored
Catch all exceptions in render-test (shader-slang#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
1 parent e22c0b7 commit 4fa76f3

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

cmake/CompilerFlags.cmake

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ function(add_supported_cxx_flags target)
1616
endif()
1717

1818
foreach(flag ${flags})
19+
# /EHa enables SEH on Windows, it is not available in Linux.
20+
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
21+
string(REGEX REPLACE "/EHa" "" flag "${flag}")
22+
endif()
1923
# remove the `no-` prefix from warnings because gcc doesn't treat it as an
2024
# error on its own
2125
string(REGEX REPLACE "\\-Wno\\-(.+)" "-W\\1" flag_to_test "${flag}")

cmake/SlangTarget.cmake

+3-2
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,10 @@ function(slang_add_target dir type)
337337
)
338338
endif()
339339
if(ARG_EXTRA_COMPILE_OPTIONS_PRIVATE)
340-
target_compile_options(
340+
add_supported_cxx_flags(
341341
${target}
342-
PRIVATE ${ARG_EXTRA_COMPILE_OPTIONS_PRIVATE}
342+
PRIVATE
343+
${ARG_EXTRA_COMPILE_OPTIONS_PRIVATE}
343344
)
344345
endif()
345346

tools/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ if(SLANG_ENABLE_TESTS)
276276
EXTRA_COMPILE_DEFINITIONS_PRIVATE
277277
$<$<BOOL:${SLANG_ENABLE_CUDA}>:RENDER_TEST_CUDA>
278278
$<$<BOOL:${SLANG_ENABLE_OPTIX}>:RENDER_TEST_OPTIX>
279+
EXTRA_COMPILE_OPTIONS_PRIVATE /EHa
279280
OUTPUT_NAME render-test-tool
280281
REQUIRED_BY slang-test
281282
FOLDER test/tools

0 commit comments

Comments
 (0)