Skip to content

Commit 92e64f4

Browse files
sherry-yuanpcolberg
authored andcommitted
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)
1 parent 5164893 commit 92e64f4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,20 @@ if(ACL_WITH_ASAN)
200200
endforeach()
201201
endif()
202202

203+
# https://clang.llvm.org/docs/ThreadSanitizer.html
204+
# https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fsanitize_003dthread
205+
option(ACL_TSAN "Build with thread sanitizer" OFF)
206+
message(STATUS "Build with thread sanitizer: ${ACL_TSAN}")
207+
if(ACL_TSAN)
208+
foreach(lang C CXX)
209+
if(CMAKE_${lang}_COMPILER_ID MATCHES "^(Clang|GNU)$")
210+
set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -fsanitize=thread -fno-omit-frame-pointer")
211+
else()
212+
message(FATAL_ERROR "cannot build with thread sanitizer due to unsupported ${lang} compiler")
213+
endif()
214+
endforeach()
215+
endif()
216+
203217
include(CPack)
204218
include(CTest)
205219

0 commit comments

Comments
 (0)