diff --git a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp index 5485998164f1e..0d48a350254ee 100644 --- a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp @@ -80,6 +80,10 @@ static cl::opt ClCompoundReadBeforeWrite( "tsan-compound-read-before-write", cl::init(false), cl::desc("Emit special compound instrumentation for reads-before-writes"), cl::Hidden); +static cl::opt + 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,8 @@ 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).