| 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: &barrier); |
| 16 | long res = foo(cond: (long)p); |
| 17 | return (void*) res; |
| 18 | } |
| 19 | |
| 20 | int main() { |
| 21 | barrier_init(barrier: &barrier, count: 2); |
| 22 | pthread_t t; |
| 23 | pthread_create(newthread: &t, attr: 0, start_routine: Thread1, arg: 0); |
| 24 | g = 1; |
| 25 | barrier_wait(barrier: &barrier); |
| 26 | pthread_join(th: t, thread_return: 0); |
| 27 | fprintf(stderr, format: "PASS\n"); |
| 28 | // CHECK-NOT: ThreadSanitizer: data race |
| 29 | // CHECK: PASS |
| 30 | } |
| 31 |
