diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 264a19f..5ed35f7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 354d9be..b23d067 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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")