[compiler-rt] r298378 - tsan: support __ATOMIC_HLE_ACQUIRE/RELEASE flags
Sean Silva via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 21 12:50:01 PDT 2017
s/covert_morder/convert_morder/ ?
On Tuesday, March 21, 2017, Dmitry Vyukov via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Author: dvyukov
> Date: Tue Mar 21 09:28:55 2017
> New Revision: 298378
>
> URL: http://llvm.org/viewvc/llvm-project?rev=298378&view=rev
> Log:
> tsan: support __ATOMIC_HLE_ACQUIRE/RELEASE flags
>
> HLE flags can be combined with memory order in atomic operations.
> Currently tsan runtime crashes on e.g. IsStoreOrder(mo) in atomic store
> if any of these additional flags are specified.
>
> Filter these flags out.
> See the comment as to why it is safe.
>
>
> Added:
> compiler-rt/trunk/test/tsan/atomic_hle.cc
> Modified:
> compiler-rt/trunk/lib/tsan/rtl/tsan_interface_atomic.cc
>
> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interface_atomic.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/
> tsan/rtl/tsan_interface_atomic.cc?rev=298378&r1=298377&r2=298378&view=diff
> ============================================================
> ==================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_interface_atomic.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_interface_atomic.cc Tue Mar 21
> 09:28:55 2017
> @@ -450,10 +450,27 @@ static void AtomicFence(ThreadState *thr
>
> // 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__); \
>
> Added: compiler-rt/trunk/test/tsan/atomic_hle.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/
> test/tsan/atomic_hle.cc?rev=298378&view=auto
> ============================================================
> ==================
> --- compiler-rt/trunk/test/tsan/atomic_hle.cc (added)
> +++ compiler-rt/trunk/test/tsan/atomic_hle.cc Tue Mar 21 09:28:55 2017
> @@ -0,0 +1,25 @@
> +// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
> +#include "test.h"
> +#include <sanitizer/tsan_interface_atomic.h>
> +
> +#ifndef __ATOMIC_HLE_ACQUIRE
> +#define __ATOMIC_HLE_ACQUIRE (1 << 16)
> +#endif
> +#ifndef __ATOMIC_HLE_RELEASE
> +#define __ATOMIC_HLE_RELEASE (1 << 17)
> +#endif
> +
> +int main() {
> + volatile int x = 0;
> + //__atomic_fetch_add(&x, 1, __ATOMIC_ACQUIRE | __ATOMIC_HLE_ACQUIRE);
> + //__atomic_store_n(&x, 0, __ATOMIC_RELEASE | __ATOMIC_HLE_RELEASE);
> + __tsan_atomic32_fetch_add(&x, 1,
> + (__tsan_memory_order)(__ATOMIC_ACQUIRE | __ATOMIC_HLE_ACQUIRE));
> + __tsan_atomic32_store(&x, 0,
> + (__tsan_memory_order)(__ATOMIC_RELEASE | __ATOMIC_HLE_RELEASE));
> + fprintf(stderr, "DONE\n");
> + return 0;
> +}
> +
> +// CHECK: DONE
> +
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org <javascript:;>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170321/4dc9e715/attachment.html>
More information about the llvm-commits
mailing list