diff --git a/CMakeLists.txt b/CMakeLists.txt index 84404d1108..b8e58472ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ option(UR_FORMAT_CPP_STYLE "format code style of C++ sources" OFF) option(UR_USE_ASAN "enable AddressSanitizer" OFF) option(UR_USE_UBSAN "enable UndefinedBehaviorSanitizer" OFF) option(UR_USE_MSAN "enable MemorySanitizer" OFF) +option(UR_USE_TSAN "enable ThreadSanitizer" OFF) option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF) option(UR_ENABLE_TRACING "enable api tracing through xpti" OFF) option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace for linux" OFF) @@ -117,6 +118,10 @@ if(UR_USE_UBSAN) add_sanitizer_flag(undefined) endif() +if(UR_USE_TSAN) + add_sanitizer_flag(thread) +endif() + if(UR_USE_MSAN) message(WARNING "MemorySanitizer requires that all code is built with its instrumentation, otherwise false positives are possible. diff --git a/README.md b/README.md index 534a198573..b0583f5ba4 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ List of options provided by CMake: | UR_FORMAT_CPP_STYLE | Format code style | ON/OFF | OFF | | UR_DEVELOPER_MODE | Treat warnings as errors and enables additional checks | ON/OFF | OFF | | UR_USE_ASAN | Enable AddressSanitizer | ON/OFF | OFF | +| UR_USE_TSAN | Enable ThreadSanitizer | ON/OFF | OFF | | UR_USE_UBSAN | Enable UndefinedBehavior Sanitizer | ON/OFF | OFF | | UR_USE_MSAN | Enable MemorySanitizer (clang only) | ON/OFF | OFF | | UR_ENABLE_TRACING | Enable XPTI-based tracing layer | ON/OFF | OFF | diff --git a/source/common/ur_util.hpp b/source/common/ur_util.hpp index 54617d7c87..8276d10048 100644 --- a/source/common/ur_util.hpp +++ b/source/common/ur_util.hpp @@ -42,13 +42,19 @@ inline int ur_getpid(void) { return static_cast(getpid()); } #define SANITIZER_ADDRESS #endif +/* define for running with memory sanitizer */ +#if CLANG_HAS_FEATURE(thread_sanitizer) || defined(__SANITIZE_THREAD__) +#define SANITIZER_THREAD +#endif + /* define for running with memory sanitizer */ #if CLANG_HAS_FEATURE(memory_sanitizer) #define SANITIZER_MEMORY #endif /* define for running with any sanitizer runtime */ -#if defined(SANITIZER_MEMORY) || defined(SANITIZER_ADDRESS) +#if defined(SANITIZER_MEMORY) || defined(SANITIZER_ADDRESS) || \ + defined(SANITIZER_THREAD) #define SANITIZER_ANY #endif ///////////////////////////////////////////////////////////////////////////////