]> git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/tsan/race_on_speculative_load.cc
New upstream version 1.19.0+dfsg3
[rustc.git] / src / compiler-rt / test / tsan / race_on_speculative_load.cc
1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 // Regtest for https://github.com/google/sanitizers/issues/447
3 // This is a correct program and tsan should not report a race.
4 #include "test.h"
5
6 int g;
7 __attribute__((noinline))
8 int foo(int cond) {
9 if (cond)
10 return g;
11 return 0;
12 }
13
14 void *Thread1(void *p) {
15 barrier_wait(&barrier);
16 long res = foo((long)p);
17 return (void*) res;
18 }
19
20 int main() {
21 barrier_init(&barrier, 2);
22 pthread_t t;
23 pthread_create(&t, 0, Thread1, 0);
24 g = 1;
25 barrier_wait(&barrier);
26 pthread_join(t, 0);
27 fprintf(stderr, "PASS\n");
28 // CHECK-NOT: ThreadSanitizer: data race
29 // CHECK: PASS
30 }