https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78158
--- Comment #14 from Dmitry Vyukov <dvyukov at google dot com> --- Right, we need to catch completely bogus values. But the question is: are these values extending up or down? :) Because special flag was added after the HLE flags... So how about 12 bits? :) --- lib/tsan/rtl/tsan_interface_atomic.cc (revision 298354) +++ lib/tsan/rtl/tsan_interface_atomic.cc (working copy) @@ -450,10 +450,30 @@ // 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's unclear if these special flags extend up or down, because + // MEMMODEL_SYNC was added after HLE flags. So we mask lower 12 bits to + // allow some future special flags and catch completely bogus memory order + // values at the same time. + return mo & 0xfff; +} + #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__); \