Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / java_race.cpp
blob140a2a3c19d3b34689bd2b1f1dee989b0d9fcb6b
1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2 #include "java.h"
4 void *Thread(void *p) {
5 barrier_wait(&barrier);
6 *(int*)p = 42;
7 return 0;
10 int main() {
11 barrier_init(&barrier, 2);
12 int const kHeapSize = 1024 * 1024;
13 jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;
14 __tsan_java_init(jheap, kHeapSize);
15 const int kBlockSize = 16;
16 __tsan_java_alloc(jheap, kBlockSize);
17 pthread_t th;
18 pthread_create(&th, 0, Thread, (void*)jheap);
19 *(int*)jheap = 43;
20 barrier_wait(&barrier);
21 pthread_join(th, 0);
22 __tsan_java_free(jheap, kBlockSize);
23 fprintf(stderr, "DONE\n");
24 return __tsan_java_fini();
27 // CHECK: WARNING: ThreadSanitizer: data race
28 // CHECK: DONE