Enable sanitizers in CI.

This commit is contained in:
Matthew Parkinson
2021-12-15 11:46:55 +00:00
committed by Matthew Parkinson
parent 0fd5c37563
commit 4f2d3ebf33
2 changed files with 15 additions and 0 deletions

View File

@@ -78,6 +78,10 @@ jobs:
dependencies: "sudo apt install ninja-build"
extra-cmake-flags: "-DCMAKE_CXX_COMPILER=clang++-10 -DCMAKE_C_COMPILER=clang-10 -DCMAKE_CXX_FLAGS=-stdlib=libstdc++"
build-only: yes
- os: "ubuntu-latest"
variant: Clang 10 libc++ (TSan + UBSan)
dependencies: "sudo apt install ninja-build"
extra-cmake-flags: "-DCMAKE_CXX_COMPILER=clang++-10 -DCMAKE_C_COMPILER=clang-10 -DCMAKE_CXX_FLAGS=-stdlib=libc++ -DSNMALLOC_SANITIZER=undefined,thread"
# Don't abort runners if a single one fails
fail-fast: false
runs-on: ${{ matrix.os }}

View File

@@ -47,6 +47,11 @@ if (NOT SNMALLOC_CLEANUP STREQUAL CXX11_DESTRUCTORS)
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
endif()
set(SNMALLOC_SANITIZER "" CACHE STRING "Use sanitizer type (undefined|thread|...)")
if (SNMALLOC_SANITIZER)
message(STATUS "Using sanitizer=${SNMALLOC_SANITIZER}")
endif()
# If CheckLinkerFlag doesn't exist then provide a dummy implementation that
# always fails. The fallback can be removed when we move to CMake 3.18 as the
# baseline.
@@ -374,6 +379,12 @@ if(NOT SNMALLOC_HEADER_ONLY_LIBRARY)
set(TESTNAME "${TEST_CATEGORY}-${TEST}-${FLAVOUR}")
add_executable(${TESTNAME} ${SRC})
if(SNMALLOC_SANITIZER)
target_compile_options(${TESTNAME} PRIVATE -g -fsanitize=${SNMALLOC_SANITIZER} -fno-omit-frame-pointer)
target_link_libraries(${TESTNAME} -fsanitize=${SNMALLOC_SANITIZER})
endif()
add_warning_flags(${TESTNAME})
if (${FLAVOUR} STREQUAL "malloc")