[PATCH] D23061: [tsan] Fix the behavior of OSAtomicTestAndClear
Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 2 07:38:38 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL277461: [tsan] Fix the behavior of OSAtomicTestAndClear (authored by kuba.brecka).
Changed prior to commit:
https://reviews.llvm.org/D23061?vs=66471&id=66476#toc
Repository:
rL LLVM
https://reviews.llvm.org/D23061
Files:
compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors_mac.cc
compiler-rt/trunk/test/tsan/Darwin/osatomics-bitops.mm
Index: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors_mac.cc
===================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors_mac.cc
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors_mac.cc
@@ -119,24 +119,23 @@
OSATOMIC_INTERCEPTORS_CAS(OSAtomicCompareAndSwap64, __tsan_atomic64, a64,
int64_t)
-#define OSATOMIC_INTERCEPTOR_BITOP(f, op, m, mo) \
+#define OSATOMIC_INTERCEPTOR_BITOP(f, op, clear, mo) \
TSAN_INTERCEPTOR(bool, f, uint32_t n, volatile void *ptr) { \
SCOPED_TSAN_INTERCEPTOR(f, n, ptr); \
char *byte_ptr = ((char *)ptr) + (n >> 3); \
- char bit_index = n & 7; \
- char mask = m; \
+ char bit = 0x80u >> (n & 7); \
+ char mask = clear ? ~bit : bit; \
char orig_byte = op((a8 *)byte_ptr, mask, mo); \
- return orig_byte & mask; \
+ return orig_byte & bit; \
}
-#define OSATOMIC_INTERCEPTORS_BITOP(f, op, m) \
- OSATOMIC_INTERCEPTOR_BITOP(f, op, m, kMacOrderNonBarrier) \
- OSATOMIC_INTERCEPTOR_BITOP(f##Barrier, op, m, kMacOrderBarrier)
+#define OSATOMIC_INTERCEPTORS_BITOP(f, op, clear) \
+ OSATOMIC_INTERCEPTOR_BITOP(f, op, clear, kMacOrderNonBarrier) \
+ OSATOMIC_INTERCEPTOR_BITOP(f##Barrier, op, clear, kMacOrderBarrier)
-OSATOMIC_INTERCEPTORS_BITOP(OSAtomicTestAndSet, __tsan_atomic8_fetch_or,
- 0x80u >> bit_index)
+OSATOMIC_INTERCEPTORS_BITOP(OSAtomicTestAndSet, __tsan_atomic8_fetch_or, false)
OSATOMIC_INTERCEPTORS_BITOP(OSAtomicTestAndClear, __tsan_atomic8_fetch_and,
- ~(0x80u >> bit_index))
+ true)
TSAN_INTERCEPTOR(void, OSAtomicEnqueue, OSQueueHead *list, void *item,
size_t offset) {
Index: compiler-rt/trunk/test/tsan/Darwin/osatomics-bitops.mm
===================================================================
--- compiler-rt/trunk/test/tsan/Darwin/osatomics-bitops.mm
+++ compiler-rt/trunk/test/tsan/Darwin/osatomics-bitops.mm
@@ -0,0 +1,34 @@
+// RUN: %clangxx_tsan %s -o %t -framework Foundation -std=c++11
+// RUN: %run %t 2>&1 | FileCheck %s
+
+#import <Foundation/Foundation.h>
+#import <libkern/OSAtomic.h>
+
+int main(int argc, const char *argv[]) {
+ int value = 1;
+ bool ret = OSAtomicTestAndClear(7, &value);
+ fprintf(stderr, "value = %d, ret = %d\n", value, ret);
+ // CHECK: value = 0, ret = 1
+
+ ret = OSAtomicTestAndSet(4, &value);
+ fprintf(stderr, "value = %d, ret = %d\n", value, ret);
+ // CHECK: value = 8, ret = 0
+
+ ret = OSAtomicTestAndClear(4, &value);
+ fprintf(stderr, "value = %d, ret = %d\n", value, ret);
+ // CHECK: value = 0, ret = 1
+
+ ret = OSAtomicTestAndSet(12, &value);
+ fprintf(stderr, "value = %d, ret = %d\n", value, ret);
+ // CHECK: value = 2048, ret = 0
+
+ ret = OSAtomicTestAndSet(13, &value);
+ fprintf(stderr, "value = %d, ret = %d\n", value, ret);
+ // CHECK: value = 3072, ret = 0
+
+ ret = OSAtomicTestAndClear(12, &value);
+ fprintf(stderr, "value = %d, ret = %d\n", value, ret);
+ // CHECK: value = 1024, ret = 1
+
+ return 0;
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23061.66476.patch
Type: text/x-patch
Size: 3389 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160802/9bb8c4e6/attachment.bin>
More information about the llvm-commits
mailing list