From 4b3aa089d97ad4eda46565021c83abf47b90381c Mon Sep 17 00:00:00 2001 From: Sherry Yuan Date: Tue, 8 Feb 2022 07:47:15 -0800 Subject: [PATCH] Add thread sanitizer option to cmake ---------------------------------------------- Thread sanitizer (TSAN) is a tool that detect data races, deadlocks between threads. (it also sometimes report heap-use-after-free in same thread check #71 for issues reported in current repo) For more information, checkout https://clang.llvm.org/docs/ThreadSanitizer.html --- CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ac8a0c6..8e84ba8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,18 @@ if(ACL_CODE_COVERAGE) endif() endif() +# Flag for tsan scans +option(ACL_TSAN "Build with tsan" OFF) +message(STATUS "Build with tsan: ${ACL_TSAN}") +if(ACL_TSAN) + if(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -fno-omit-frame-pointer") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread -fno-omit-frame-pointer") + else() + message(FATAL_ERROR "cannot build with tsan tools due to unsupported CXX compiler") + endif() +endif() + ################################################################################ ### Modified Debug flags ################################################################################