[compiler-rt] [TSan] Fix spurious 'thread finished with ignores enabled' warning on FreeBSD (PR #155399)
Dan Blackwell via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 26 04:59:06 PDT 2025
https://github.com/DanBlackwell created https://github.com/llvm/llvm-project/pull/155399
This fixes a false positive error report on FreeBSD under certain circumstances. The error occurs in the thr_exit interceptor as follows:
* `SCOPED_TSAN_INTERCEPTOR` macro calls the `ScopedInterceptor` constructor -> `EnableIgnores` -> `EnableIgnoresImpl`, which increments `thr_->suppress_reports`.
* `DestroyThreadState` -> `ThreadFinish` -> `ReportIgnoresEnabled` then fires off a warning, as `thr_->suppress_reports` is non-zero.
To avoid this spurious error, we follow the example of the `pthread_exit` interceptor, and take an anonymous scope so that the `ScopedInterceptor` destructor gets called before `DestroyThreadState`, decrementing `suppress_reports` back to 0.
>From f3e051129734458e6878e8f58a9fb3c7415926f8 Mon Sep 17 00:00:00 2001
From: Dan Blackwell <dan_blackwell at apple.com>
Date: Tue, 26 Aug 2025 12:36:53 +0100
Subject: [PATCH] [TSan] Fix spurious 'thread finished with ignores enabled'
warning on FreeBSD
This fixes a false positive error report on FreeBSD under certain circumstances. The error occurs in the thr_exit interceptor as follows:
* `SCOPED_TSAN_INTERCEPTOR` macro calls the `ScopedInterceptor` constructor -> `EnableIgnores` -> `EnableIgnoresImpl`, which increments `thr_->suppress_reports`.
* `DestroyThreadState` -> `ThreadFinish` -> `ReportIgnoresEnabled` then fires off a warning, as `thr_->suppress_reports` is non-zero.
To avoid this spurious error, we follow the example of the `pthread_exit` interceptor, and take an anonymous scope so that the `ScopedInterceptor` destructor gets called before `DestroyThreadState`, decrementing `suppress_reports` back to 0.
---
compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
index b46a81031258c..8bb872f0148a9 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
@@ -2890,7 +2890,9 @@ TSAN_INTERCEPTOR(void, _lwp_exit) {
#if SANITIZER_FREEBSD
TSAN_INTERCEPTOR(void, thr_exit, ThreadID *state) {
- SCOPED_TSAN_INTERCEPTOR(thr_exit, state);
+ {
+ SCOPED_TSAN_INTERCEPTOR(thr_exit, state);
+ }
DestroyThreadState();
REAL(thr_exit(state));
}
More information about the llvm-commits
mailing list