Skip to content

Commit 0f7d9da

Browse files
committed
Fix false positive in tsan (fixes #4755)
1 parent eeff868 commit 0f7d9da

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

include/fmt/format-inl.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
#ifndef FMT_FORMAT_INL_H_
99
#define FMT_FORMAT_INL_H_
1010

11+
#ifdef __SANITIZE_THREAD__
12+
extern "C" void __tsan_acquire(void*);
13+
extern "C" void __tsan_release(void*);
14+
#endif
15+
1116
#ifndef FMT_MODULE
1217
# include <stddef.h> // ptrdiff_t
1318

@@ -1696,6 +1701,9 @@ class file_print_buffer<F, enable_if_t<has_flockfile<F>::value>>
16961701
public:
16971702
explicit file_print_buffer(F* f) : buffer(grow, size_t()), file_(f) {
16981703
flockfile(f);
1704+
#ifdef __SANITIZE_THREAD__
1705+
__tsan_acquire(f);
1706+
#endif
16991707
file_.init_buffer();
17001708
auto buf = file_.get_write_buffer();
17011709
set(buf.data, buf.size);
@@ -1705,6 +1713,9 @@ class file_print_buffer<F, enable_if_t<has_flockfile<F>::value>>
17051713
bool flush = file_.needs_flush();
17061714
F* f = file_; // Make funlockfile depend on the template parameter F
17071715
funlockfile(f); // for the system API detection to work.
1716+
#ifdef __SANITIZE_THREAD__
1717+
__tsan_release(f);
1718+
#endif
17081719
if (flush) fflush(file_);
17091720
}
17101721
};

0 commit comments

Comments
 (0)