Avoid triggering assert when program calls OSAtomicCompareAndSwapLong
authorJulian Lettner <julian.lettner@apple.com>
Mon, 12 Jul 2021 21:00:45 +0000 (14:00 -0700)
committerJulian Lettner <julian.lettner@apple.com>
Tue, 13 Jul 2021 16:33:50 +0000 (09:33 -0700)
commit1893b630fec06947b4f59e43c00db4d787f39262
tree6d1b03751ea373cc1b7e15bc1144dbcf3e065742
parent68ae8bacfce3b9bd73fefb0d28efd461e1588586
Avoid triggering assert when program calls OSAtomicCompareAndSwapLong

A previous change brought the new, relaxed implementation of "on failure
memory ordering" for synchronization primitives in LLVM over to TSan
land [1].  It included the following assert:
```
// 31.7.2.18: "The failure argument shall not be memory_order_release
// nor memory_order_acq_rel". LLVM (2021-05) fallbacks to Monotonic
// (mo_relaxed) when those are used.
CHECK(IsLoadOrder(fmo));

static bool IsLoadOrder(morder mo) {
  return mo == mo_relaxed || mo == mo_consume
      || mo == mo_acquire || mo == mo_seq_cst;
}
```

A previous workaround for a false positive when using an old Darwin
synchronization API assumed this failure mode to be unused and passed a
dummy value [2].  We update this value to `mo_relaxed` which is also the
value used by the actual implementation to avoid triggering the assert.

[1] https://reviews.llvm.org/D99434
[2] https://reviews.llvm.org/D21733

rdar://78122243

Differential Revision: https://reviews.llvm.org/D105844
compiler-rt/lib/tsan/rtl/tsan_interceptors_mac.cpp