Skip to content

Commit 3621fbe

Browse files
committed
Add ThreadSanitizer option
1 parent d3fa9ca commit 3621fbe

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ option(UR_FORMAT_CPP_STYLE "format code style of C++ sources" OFF)
3030
option(UR_USE_ASAN "enable AddressSanitizer" OFF)
3131
option(UR_USE_UBSAN "enable UndefinedBehaviorSanitizer" OFF)
3232
option(UR_USE_MSAN "enable MemorySanitizer" OFF)
33+
option(UR_USE_TSAN "enable ThreadSanitizer" OFF)
3334
option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF)
3435
option(UR_ENABLE_TRACING "enable api tracing through xpti" OFF)
3536
option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace for linux" OFF)
@@ -116,6 +117,10 @@ if(UR_USE_UBSAN)
116117
add_sanitizer_flag(undefined)
117118
endif()
118119

120+
if(UR_USE_TSAN)
121+
add_sanitizer_flag(thread)
122+
endif()
123+
119124
if(UR_USE_MSAN)
120125
message(WARNING "MemorySanitizer requires that all code is built with
121126
its instrumentation, otherwise false positives are possible.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ List of options provided by CMake:
108108
| UR_FORMAT_CPP_STYLE | Format code style | ON/OFF | OFF |
109109
| UR_DEVELOPER_MODE | Treat warnings as errors and enables additional checks | ON/OFF | OFF |
110110
| UR_USE_ASAN | Enable AddressSanitizer | ON/OFF | OFF |
111+
| UR_USE_TSAN | Enable ThreadSanitizer | ON/OFF | OFF |
111112
| UR_USE_UBSAN | Enable UndefinedBehavior Sanitizer | ON/OFF | OFF |
112113
| UR_USE_MSAN | Enable MemorySanitizer (clang only) | ON/OFF | OFF |
113114
| UR_ENABLE_TRACING | Enable XPTI-based tracing layer | ON/OFF | OFF |

source/common/ur_util.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,19 @@ inline int ur_getpid(void) { return static_cast<int>(getpid()); }
4242
#define SANITIZER_ADDRESS
4343
#endif
4444

45+
/* define for running with memory sanitizer */
46+
#if CLANG_HAS_FEATURE(thread_sanitizer) || defined(__SANITIZE_THREAD__)
47+
#define SANITIZER_THREAD
48+
#endif
49+
4550
/* define for running with memory sanitizer */
4651
#if CLANG_HAS_FEATURE(memory_sanitizer)
4752
#define SANITIZER_MEMORY
4853
#endif
4954

5055
/* define for running with any sanitizer runtime */
51-
#if defined(SANITIZER_MEMORY) || defined(SANITIZER_ADDRESS)
56+
#if defined(SANITIZER_MEMORY) || defined(SANITIZER_ADDRESS) || \
57+
defined(SANITIZER_THREAD)
5258
#define SANITIZER_ANY
5359
#endif
5460
///////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)