1// RUN: %clangxx_tsan %s -o %t -framework Foundation -std=c++11
2// RUN: %run %t 2>&1 | FileCheck %s
3
4#import <Foundation/Foundation.h>
5#import <libkern/OSAtomic.h>
6
7int main(int argc, const char *argv[]) {
8 int value = 1;
9 bool ret = OSAtomicTestAndClear(7, &value);
10 fprintf(stderr, "value = %d, ret = %d\n", value, ret);
11 // CHECK: value = 0, ret = 1
12
13 ret = OSAtomicTestAndSet(4, &value);
14 fprintf(stderr, "value = %d, ret = %d\n", value, ret);
15 // CHECK: value = 8, ret = 0
16
17 ret = OSAtomicTestAndClear(4, &value);
18 fprintf(stderr, "value = %d, ret = %d\n", value, ret);
19 // CHECK: value = 0, ret = 1
20
21 ret = OSAtomicTestAndSet(12, &value);
22 fprintf(stderr, "value = %d, ret = %d\n", value, ret);
23 // CHECK: value = 2048, ret = 0
24
25 ret = OSAtomicTestAndSet(13, &value);
26 fprintf(stderr, "value = %d, ret = %d\n", value, ret);
27 // CHECK: value = 3072, ret = 0
28
29 ret = OSAtomicTestAndClear(12, &value);
30 fprintf(stderr, "value = %d, ret = %d\n", value, ret);
31 // CHECK: value = 1024, ret = 1
32
33 return 0;
34}
35

source code of compiler-rt/test/tsan/Darwin/osatomics-bitops.mm