summaryrefslogtreecommitdiff
path: root/libsanitizer/tsan
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2017-03-22 19:46:54 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2017-03-22 19:46:54 +0100
commitfd6cba40e198d145bc53502e258db560936f2226 (patch)
treec91dc8243a475c9d537229a81e5ccddb8e307c6d /libsanitizer/tsan
parent68ed2ba0a7d60275ac044a4cb50b33eb33fbb813 (diff)
downloadgcc-fd6cba40e198d145bc53502e258db560936f2226.tar.gz
re PR sanitizer/78158 (Strange data race detection with thread sanitizer)
PR sanitizer/78158 * tsan/tsan_interface_atomic.cc: Cherry-pick upstream r298378. From-SVN: r246402
Diffstat (limited to 'libsanitizer/tsan')
-rw-r--r--libsanitizer/tsan/tsan_interface_atomic.cc19
1 files changed, 18 insertions, 1 deletions
diff --git a/libsanitizer/tsan/tsan_interface_atomic.cc b/libsanitizer/tsan/tsan_interface_atomic.cc
index 5c5c34f3b87..deb4206a624 100644
--- a/libsanitizer/tsan/tsan_interface_atomic.cc
+++ b/libsanitizer/tsan/tsan_interface_atomic.cc
@@ -448,10 +448,27 @@ static void AtomicFence(ThreadState *thr, uptr pc, morder mo) {
// C/C++
+static morder covert_morder(morder mo) {
+ if (flags()->force_seq_cst_atomics)
+ return (morder)mo_seq_cst;
+
+ // Filter out additional memory order flags:
+ // MEMMODEL_SYNC = 1 << 15
+ // __ATOMIC_HLE_ACQUIRE = 1 << 16
+ // __ATOMIC_HLE_RELEASE = 1 << 17
+ //
+ // HLE is an optimization, and we pretend that elision always fails.
+ // MEMMODEL_SYNC is used when lowering __sync_ atomics,
+ // since we use __sync_ atomics for actual atomic operations,
+ // we can safely ignore it as well. It also subtly affects semantics,
+ // but we don't model the difference.
+ return (morder)(mo & 0x7fff);
+}
+
#define SCOPED_ATOMIC(func, ...) \
const uptr callpc = (uptr)__builtin_return_address(0); \
uptr pc = StackTrace::GetCurrentPc(); \
- mo = flags()->force_seq_cst_atomics ? (morder)mo_seq_cst : mo; \
+ mo = covert_morder(mo); \
ThreadState *const thr = cur_thread(); \
if (thr->ignore_interceptors) \
return NoTsanAtomic##func(__VA_ARGS__); \