[clang] [Clang] Warn when `std::atomic_thread_fence` is used with `fsanitize=thread` (PR #166542)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 5 07:54:48 PST 2025


================
@@ -0,0 +1,11 @@
+// RUN: %clang -std=c++17 %s 2>&1 | FileCheck %s --check-prefix=NO-TSAN --allow-empty
+// RUN: %clang -std=c++17 -fsanitize=thread %s 2>&1 | FileCheck %s --check-prefix=WITH-TSAN
+
+// WITH-TSAN: `std::atomic_thread_fence` is not supported with `-fsanitize=thread`
+// NO-TSAN-NOT: `std::atomic_thread_fence` is not supported with `-fsanitize=thread`
+
+#include <atomic>
----------------
AaronBallman wrote:

Please do not include system headers; that makes the test non-hermetic. Instead, manually add just the declarations needed for the test case.

Some other test cases to add: use of `no_sanitize("thread")` and `no_sanitize_thread` attributes on the function using `atomic_thread_fence`.

https://github.com/llvm/llvm-project/pull/166542


More information about the cfe-commits mailing list