[llvm] [TSan] Add option to ignore capturing behavior when instrumenting (PR #148156)
Yussur Mustafa Oraji via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 11 01:52:34 PDT 2025
https://github.com/N00byKing created https://github.com/llvm/llvm-project/pull/148156
While not needed for most applications, some tools such as [MUST](https://www.i12.rwth-aachen.de/cms/i12/forschung/forschungsschwerpunkte/lehrstuhl-fuer-hochleistungsrechnen/~nrbe/must/) depend on the instrumentation being present.
MUST uses the ThreadSanitizer annotation interface to detect data races in MPI programs, where the capture tracking is detrimental as it has no bearing on MPI data races, leading to missed races.
>From 3acc0c0041690e65d084c5e948157da048448104 Mon Sep 17 00:00:00 2001
From: Yussur Mustafa Oraji <yussur.oraji at tu-darmstadt.de>
Date: Fri, 11 Jul 2025 10:43:27 +0200
Subject: [PATCH] [TSan] Add option to ignore capturing behavior when
instrumenting
Required for some tools depending on the annotation interface
---
llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
index 5485998164f1e..d24ee09abebe5 100644
--- a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
@@ -80,6 +80,10 @@ static cl::opt<bool> ClCompoundReadBeforeWrite(
"tsan-compound-read-before-write", cl::init(false),
cl::desc("Emit special compound instrumentation for reads-before-writes"),
cl::Hidden);
+static cl::opt<bool> ClOmitNonCaptured(
+ "tsan-omit-by-pointer-capturing", cl::init(true),
+ cl::desc("Omit accesses due to pointer capturing"),
+ cl::Hidden);
STATISTIC(NumInstrumentedReads, "Number of instrumented reads");
STATISTIC(NumInstrumentedWrites, "Number of instrumented writes");
@@ -450,7 +454,7 @@ void ThreadSanitizer::chooseInstructionsToInstrument(
const AllocaInst *AI = findAllocaForValue(Addr);
// Instead of Addr, we should check whether its base pointer is captured.
- if (AI && !PointerMayBeCaptured(AI, /*ReturnCaptures=*/true)) {
+ if (AI && !PointerMayBeCaptured(AI, /*ReturnCaptures=*/true) && ClOmitNonCaptured) {
// The variable is addressable but not captured, so it cannot be
// referenced from a different thread and participate in a data race
// (see llvm/Analysis/CaptureTracking.h for details).
More information about the llvm-commits
mailing list