Skip to content

Commit 6cdf8a7

Browse files
Martin Ågrengitster
Martin Ågren
authored andcommitted
ThreadSanitizer: add suppressions
Add a file .tsan-suppressions and list two functions in it: want_color() and transfer_debug(). Both of these use the pattern static int foo = -1; if (foo < 0) foo = bar(); where bar always returns the same non-negative value. This can cause ThreadSanitizer to diagnose a race when foo is written from two threads. That is indeed a race, although it arguably doesn't matter in practice since it's always the same value that is written. Add NEEDSWORK-comments to the functions so that this problem is not forever swept way under the carpet. The suppressions-file is used by setting the environment variable TSAN_OPTIONS to, e.g., "suppressions=$(pwd)/.tsan-suppressions". Observe that relative paths such as ".tsan-suppressions" might not work. Signed-off-by: Martin Ågren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 65961d5 commit 6cdf8a7

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

.tsan-suppressions

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Suppressions for ThreadSanitizer (tsan).
2+
#
3+
# This file is used by setting the environment variable TSAN_OPTIONS to, e.g.,
4+
# "suppressions=$(pwd)/.tsan-suppressions". Observe that relative paths such as
5+
# ".tsan-suppressions" might not work.
6+
7+
# A static variable is written to racily, but we always write the same value, so
8+
# in practice it (hopefully!) doesn't matter.
9+
race:^want_color$
10+
race:^transfer_debug$

color.c

+7
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,13 @@ static int check_auto_color(void)
338338

339339
int want_color(int var)
340340
{
341+
/*
342+
* NEEDSWORK: This function is sometimes used from multiple threads, and
343+
* we end up using want_auto racily. That "should not matter" since
344+
* we always write the same value, but it's still wrong. This function
345+
* is listed in .tsan-suppressions for the time being.
346+
*/
347+
341348
static int want_auto = -1;
342349

343350
if (var < 0)

transport-helper.c

+7
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,13 @@ int transport_helper_init(struct transport *transport, const char *name)
11171117
__attribute__((format (printf, 1, 2)))
11181118
static void transfer_debug(const char *fmt, ...)
11191119
{
1120+
/*
1121+
* NEEDSWORK: This function is sometimes used from multiple threads, and
1122+
* we end up using debug_enabled racily. That "should not matter" since
1123+
* we always write the same value, but it's still wrong. This function
1124+
* is listed in .tsan-suppressions for the time being.
1125+
*/
1126+
11201127
va_list args;
11211128
char msgbuf[PBUFFERSIZE];
11221129
static int debug_enabled = -1;

0 commit comments

Comments
 (0)