Skip to content

Commit 14e306f

Browse files
committed
tsan: use DCHECK instead of CHECK in atomic functions
Atomic functions are semi-hot in profiles. The CHECKs verify values passed by compiler and they never fired, so replace them with DCHECKs. Reviewed By: vitalybuka, melver Differential Revision: https://reviews.llvm.org/D107373
1 parent d3faecb commit 14e306f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

compiler-rt/lib/tsan/rtl/tsan_interface_atomic.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ using namespace __tsan;
3232
static StaticSpinMutex mutex128;
3333
#endif
3434

35+
#if SANITIZER_DEBUG
3536
static bool IsLoadOrder(morder mo) {
3637
return mo == mo_relaxed || mo == mo_consume
3738
|| mo == mo_acquire || mo == mo_seq_cst;
@@ -40,6 +41,7 @@ static bool IsLoadOrder(morder mo) {
4041
static bool IsStoreOrder(morder mo) {
4142
return mo == mo_relaxed || mo == mo_release || mo == mo_seq_cst;
4243
}
44+
#endif
4345

4446
static bool IsReleaseOrder(morder mo) {
4547
return mo == mo_release || mo == mo_acq_rel || mo == mo_seq_cst;
@@ -202,7 +204,7 @@ static memory_order to_mo(morder mo) {
202204
case mo_acq_rel: return memory_order_acq_rel;
203205
case mo_seq_cst: return memory_order_seq_cst;
204206
}
205-
CHECK(0);
207+
DCHECK(0);
206208
return memory_order_seq_cst;
207209
}
208210

@@ -220,7 +222,7 @@ static a128 NoTsanAtomicLoad(const volatile a128 *a, morder mo) {
220222

221223
template <typename T>
222224
static T AtomicLoad(ThreadState *thr, uptr pc, const volatile T *a, morder mo) {
223-
CHECK(IsLoadOrder(mo));
225+
DCHECK(IsLoadOrder(mo));
224226
// This fast-path is critical for performance.
225227
// Assume the access is atomic.
226228
if (!IsAcquireOrder(mo)) {
@@ -258,7 +260,7 @@ static void NoTsanAtomicStore(volatile a128 *a, a128 v, morder mo) {
258260
template <typename T>
259261
static void AtomicStore(ThreadState *thr, uptr pc, volatile T *a, T v,
260262
morder mo) {
261-
CHECK(IsStoreOrder(mo));
263+
DCHECK(IsStoreOrder(mo));
262264
MemoryAccess(thr, pc, (uptr)a, AccessSize<T>(), kAccessWrite | kAccessAtomic);
263265
// This fast-path is critical for performance.
264266
// Assume the access is atomic.
@@ -403,7 +405,7 @@ static bool AtomicCAS(ThreadState *thr, uptr pc, volatile T *a, T *c, T v,
403405
// 31.7.2.18: "The failure argument shall not be memory_order_release
404406
// nor memory_order_acq_rel". LLVM (2021-05) fallbacks to Monotonic
405407
// (mo_relaxed) when those are used.
406-
CHECK(IsLoadOrder(fmo));
408+
DCHECK(IsLoadOrder(fmo));
407409

408410
MemoryAccess(thr, pc, (uptr)a, AccessSize<T>(), kAccessWrite | kAccessAtomic);
409411
if (LIKELY(mo == mo_relaxed && fmo == mo_relaxed)) {

0 commit comments

Comments
 (0)