Index: lib/sanitizer_common/sanitizer_internal_defs.h =================================================================== --- lib/sanitizer_common/sanitizer_internal_defs.h +++ lib/sanitizer_common/sanitizer_internal_defs.h @@ -15,6 +15,9 @@ #include "sanitizer_platform.h" +#define STRINGIFY(A) STRINGIFY_(A) +#define STRINGIFY_(A) #A + #ifndef SANITIZER_DEBUG # define SANITIZER_DEBUG 0 #endif Index: lib/sanitizer_common/sanitizer_win_defs.h =================================================================== --- lib/sanitizer_common/sanitizer_win_defs.h +++ lib/sanitizer_common/sanitizer_win_defs.h @@ -30,10 +30,6 @@ #define WIN_SYM_PREFIX "_" #endif -// Intermediate macro to ensure the parameter is expanded before stringified. -#define STRINGIFY_(A) #A -#define STRINGIFY(A) STRINGIFY_(A) - // ----------------- A workaround for the absence of weak symbols -------------- // We don't have a direct equivalent of weak symbols when using MSVC, but we can // use the /alternatename directive to tell the linker to default a specific Index: lib/tsan/rtl/tsan_interceptors.h =================================================================== --- lib/tsan/rtl/tsan_interceptors.h +++ lib/tsan/rtl/tsan_interceptors.h @@ -1,6 +1,7 @@ #ifndef TSAN_INTERCEPTORS_H #define TSAN_INTERCEPTORS_H +#include "sanitizer_common/sanitizer_internal_defs.h" #include "sanitizer_common/sanitizer_stacktrace.h" #include "tsan_rtl.h" @@ -23,6 +24,22 @@ } // namespace __tsan +#define FUNC(...) FUNC_HELPER(__VA_ARGS__, unused) +#define FUNC_HELPER(func, ...) func + +#define COUNT(...) \ + COUNTER(__VA_ARGS__, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, NONZERO, \ + NONZERO, NONZERO, ZERO, unused) +#define COUNTER(arg1, arg2, arg3, arg4, arg5, args6, args7, arg8, arg9, arg10, \ + ...) \ + arg10 + +#define ARGS(...) ARGS_HELPER(COUNT(__VA_ARGS__), __VA_ARGS__) +#define ARGS_HELPER(num, ...) ARGS_HELPER2(num, __VA_ARGS__) +#define ARGS_HELPER2(num, ...) ARGS_##num(__VA_ARGS__) +#define ARGS_ZERO(arg) +#define ARGS_NONZERO(arg, ...) __VA_ARGS__ + #define SCOPED_INTERCEPTOR_RAW(func, ...) \ ThreadState *thr = cur_thread(); \ const uptr caller_pc = GET_CALLER_PC(); \ @@ -31,15 +48,19 @@ (void)pc; \ /**/ -#define SCOPED_TSAN_INTERCEPTOR(func, ...) \ - SCOPED_INTERCEPTOR_RAW(func, __VA_ARGS__); \ - if (REAL(func) == 0) { \ - Report("FATAL: ThreadSanitizer: failed to intercept %s\n", #func); \ - Die(); \ - } \ - if (!thr->is_inited || thr->ignore_interceptors || thr->in_ignored_lib) \ - return REAL(func)(__VA_ARGS__); \ -/**/ +#define SCOPED_TSAN_INTERCEPTOR_HELPER(func, ...) \ + SCOPED_INTERCEPTOR_RAW(func, __VA_ARGS__); \ + if (REAL(func) == 0) { \ + Report("FATAL: ThreadSanitizer: failed to intercept %s\n", \ + STRINGIFY(func)); \ + Die(); \ + } \ + if (!thr->is_inited || thr->ignore_interceptors || thr->in_ignored_lib) \ + return REAL(func)(__VA_ARGS__); \ + /**/ + +#define SCOPED_TSAN_INTERCEPTOR(...) \ + SCOPED_TSAN_INTERCEPTOR_HELPER(FUNC(__VA_ARGS__), ARGS(__VA_ARGS__)) #define SCOPED_TSAN_INTERCEPTOR_USER_CALLBACK_START() \ si.DisableIgnores(); Index: lib/tsan/rtl/tsan_interceptors.cc =================================================================== --- lib/tsan/rtl/tsan_interceptors.cc +++ lib/tsan/rtl/tsan_interceptors.cc @@ -371,7 +371,7 @@ return res; } -TSAN_INTERCEPTOR(int, pause) { +TSAN_INTERCEPTOR(int, pause, void) { SCOPED_TSAN_INTERCEPTOR(pause); return BLOCK_REAL(pause)(); }