Skip to content

Commit

Permalink
Catch2 ASAN support with Windows MSVC
Browse files Browse the repository at this point in the history
ASAN on Windows messes with exception handlers, and Catch2 doesn't
account for this. A workaround is to disable SEH on Windows with ASAN as
suggested in this reply to an existing issue
catchorg/Catch2#898 (comment)
  • Loading branch information
ekilmer committed May 16, 2021
1 parent 3212b52 commit 7434aa9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: 'true'
- name: Enable ASan Sanitizers
if: matrix.build-type == 'Debug' && matrix.build-arch == 'x64'
run: |
echo "SANITIZER_FLAG=-DPEPARSE_USE_SANITIZER=Address" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
- name: build
run: |
mkdir build
Expand All @@ -119,6 +123,7 @@ jobs:
-A ${{ matrix.build-arch }} `
-DBUILD_SHARED_LIBS=${{ matrix.build-shared }} `
-DPEPARSE_ENABLE_TESTING=ON `
$Env:SANITIZER_FLAG `
..
cmake --build . --config ${{ matrix.build-type }}
- name: install
Expand Down
8 changes: 7 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ add_executable(tests
filesystem_compat.h
)
target_compile_definitions(tests PRIVATE ASSETS_DIR="${CMAKE_CURRENT_SOURCE_DIR}/assets")
target_link_libraries(tests PRIVATE std::filesystem ${PROJECT_NAME} Catch2::Catch2)
target_include_directories(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(tests PRIVATE std::filesystem ${PROJECT_NAME} Catch2::Catch2)
# ASAN on Windows messes with exception handlers, and Catch2 doesn't account
# for this. A workaround is to disable SEH on Windows with ASAN
# https://github.com/catchorg/Catch2/issues/898#issuecomment-841733322
if (WIN32 AND PEPARSE_USE_SANITIZER STREQUAL "Address")
target_compile_definitions(tests PUBLIC CATCH_CONFIG_NO_WINDOWS_SEH)
endif()

if (EXISTS "${CORKAMI_PE_PATH}")
target_compile_definitions(tests PRIVATE CORKAMI_PE_PATH="${CORKAMI_PE_PATH}")
Expand Down

0 comments on commit 7434aa9

Please sign in to comment.