diff --git a/llvm/lib/ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp b/llvm/lib/ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp index e2b5ce49ba2ec1..cf9ed7dbff1536 100644 --- a/llvm/lib/ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp +++ b/llvm/lib/ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp @@ -60,6 +60,10 @@ class PerfJITEventListener : public JITEventListener { public: PerfJITEventListener(); ~PerfJITEventListener() { + // Lock a mutex to correctly synchronize with prior calls to + // `notifyObjectLoaded` and `notifyFreeingObject` that happened on other + // threads to prevent tsan from complaining. + std::lock_guard Guard(Mutex); if (MarkerAddr) CloseMarker(); }