Skip to content

Commit

Permalink
Merge pull request #747 from wlemkows/ur-thread-sanitizer
Browse files Browse the repository at this point in the history
Add ThreadSanitizer option
  • Loading branch information
pbalcer committed Jul 26, 2023
2 parents ae807d8 + 3621fbe commit 2826341
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
8 changes: 7 additions & 1 deletion source/common/ur_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@ inline int ur_getpid(void) { return static_cast<int>(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
///////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 2826341

Please sign in to comment.