Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / java_move_overlap_race.cpp
blobefe90b6fa7e9ceffc0149c268f15a81391ee4e7a
1 // RUN: %clangxx_tsan -O1 %s -o %t
2 // RUN: %run %t 2>&1 | FileCheck %s
3 // RUN: %run %t arg 2>&1 | FileCheck %s
4 #include "java.h"
6 jptr varaddr1_old;
7 jptr varaddr2_old;
8 jptr varaddr1_new;
9 jptr varaddr2_new;
11 void *Thread(void *p) {
12 barrier_wait(&barrier);
13 *(int*)varaddr1_new = 43;
14 *(int*)varaddr2_new = 43;
15 return 0;
18 int main(int argc, char **argv) {
19 barrier_init(&barrier, 2);
20 int const kHeapSize = 1024 * 1024;
21 void *jheap = malloc(kHeapSize);
22 jheap = (char*)jheap + 8;
23 __tsan_java_init((jptr)jheap, kHeapSize);
24 const int kBlockSize = 64;
25 int const kMove = 32;
26 varaddr1_old = (jptr)jheap;
27 varaddr2_old = (jptr)jheap + kBlockSize - 1;
28 varaddr1_new = varaddr1_old + kMove;
29 varaddr2_new = varaddr2_old + kMove;
30 if (argc > 1) {
31 // Move memory backwards.
32 varaddr1_old += kMove;
33 varaddr2_old += kMove;
34 varaddr1_new -= kMove;
35 varaddr2_new -= kMove;
37 __tsan_java_alloc(varaddr1_old, kBlockSize);
39 pthread_t th;
40 pthread_create(&th, 0, Thread, 0);
42 *(int*)varaddr1_old = 43;
43 *(int*)varaddr2_old = 43;
45 __tsan_java_move(varaddr1_old, varaddr1_new, kBlockSize);
46 barrier_wait(&barrier);
47 pthread_join(th, 0);
48 __tsan_java_free(varaddr1_new, kBlockSize);
49 fprintf(stderr, "DONE\n");
50 return __tsan_java_fini();
53 // Note: there is a race on the moved object (which we used to detect),
54 // but now __tsan_java_move resets the object shadow, so we don't detect it anymore.
55 // CHECK-NOT: WARNING: ThreadSanitizer: data race
56 // CHECK: DONE