[llvm-branch-commits] [compiler-rt] [compiler-rt] Add 'csan' library for the concurrency sanitizer (PR #225782)

Vitaly Buka via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Oct 8 10:47:44 PDT 2026


================
@@ -0,0 +1,306 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// HSA interceptors for host-side ConcurrencySanitizer offload support.
+///
+//===----------------------------------------------------------------------===//
+
+#include <dlfcn.h>
+
+#include "csan_offload.h"
+#include "interception/interception.h"
+#include "sanitizer_common/sanitizer_atomic.h"
+#include "sanitizer_common/sanitizer_common.h"
+#include "sanitizer_common/sanitizer_flag_parser.h"
+#include "sanitizer_common/sanitizer_flags.h"
+#include "sanitizer_common/sanitizer_libc.h"
+#include "sanitizer_common/sanitizer_mutex.h"
+#include "sanitizer_common/sanitizer_offload.h"
+#include "sanitizer_common/sanitizer_platform.h"
+#include "sanitizer_common/sanitizer_symbolizer.h"
+#include "sanitizer_common/sanitizer_vector.h"
+
+#if !SANITIZER_LINUX
+#error "Offload CSan reporting is supported on Linux only"
+#endif
+
+using namespace __sanitizer;
+using namespace __csan;
+
+namespace {
+
+static StaticSpinMutex InitMutex;
+static StaticSpinMutex HsaMutex;
+static atomic_uint8_t Initialized;
+static void *HsaHandle;
+
+struct DeviceAllocation {
+  hsa_agent_t Agent;
+  void *Ptr;
+};
+
+Mutex AllocationMutex;
+InternalMmapVectorNoCtor<DeviceAllocation> Allocations;
+uptr HsaRefs;
+
+void Initialize() {
+  if (LIKELY(atomic_load(&Initialized, memory_order_acquire)))
+    return;
+  SpinMutexLock L(&InitMutex);
----------------
vitalybuka wrote:

Will InitializeFlags override flags setup below?

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


More information about the llvm-branch-commits mailing list