From 92e64f436618466e70054be2209ea0f76c51d3fa Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Tue, 8 Feb 2022 07:47:15 -0800 Subject: [PATCH 1/2] Add thread sanitizer option to cmake Thread sanitizer (TSAN) is a tool that detect data races and deadlocks between threads. (It also sometimes report heap-use-after-free in same thread check #71 for issues reported in current repo) --- CMakeLists.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ac8a0c6..260d8668 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,6 +200,20 @@ if(ACL_WITH_ASAN) endforeach() endif() +# https://clang.llvm.org/docs/ThreadSanitizer.html +# https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fsanitize_003dthread +option(ACL_TSAN "Build with thread sanitizer" OFF) +message(STATUS "Build with thread sanitizer: ${ACL_TSAN}") +if(ACL_TSAN) + foreach(lang C CXX) + if(CMAKE_${lang}_COMPILER_ID MATCHES "^(Clang|GNU)$") + set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -fsanitize=thread -fno-omit-frame-pointer") + else() + message(FATAL_ERROR "cannot build with thread sanitizer due to unsupported ${lang} compiler") + endif() + endforeach() +endif() + include(CPack) include(CTest) From fba7db7d2f1c0a50110f893bda10ce0a850a797e Mon Sep 17 00:00:00 2001 From: Peter Colberg Date: Wed, 16 Feb 2022 19:40:06 -0500 Subject: [PATCH 2/2] Add link to GCC documentation for address sanitizer --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 260d8668..6eeb68a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -188,6 +188,7 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") endif() # https://clang.llvm.org/docs/AddressSanitizer.html +# https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fsanitize_003daddress option(ACL_WITH_ASAN "Build with address sanitizer" OFF) message(STATUS "Build with address sanitizer: ${ACL_WITH_ASAN}") if(ACL_WITH_ASAN)