llvm-project
37 строк · 1019.0 Байт
1// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2#include "java.h"3
4jptr varaddr;5jptr varaddr2;6
7void *Thread(void *p) {8barrier_wait(&barrier);9*(int*)varaddr2 = 42;10return 0;11}
12
13int main() {14barrier_init(&barrier, 2);15int const kHeapSize = 1024 * 1024;16jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;17__tsan_java_init(jheap, kHeapSize);18const int kBlockSize = 64;19int const kMove = 1024;20__tsan_java_alloc(jheap, kBlockSize);21varaddr = jheap + 16;22varaddr2 = varaddr + kMove;23pthread_t th;24pthread_create(&th, 0, Thread, 0);25*(int*)varaddr = 43;26__tsan_java_move(varaddr, varaddr2, kBlockSize);27barrier_wait(&barrier);28pthread_join(th, 0);29__tsan_java_free(varaddr2, kBlockSize);30fprintf(stderr, "DONE\n");31return __tsan_java_fini();32}
33
34// Note: there is a race on the moved object (which we used to detect),
35// but now __tsan_java_move resets the object shadow, so we don't detect it anymore.
36// CHECK-NOT: WARNING: ThreadSanitizer: data race
37// CHECK: DONE
38