31 lines · cpp
1// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s2// Regtest for https://github.com/google/sanitizers/issues/4473// This is a correct program and tsan should not report a race.4#include "test.h"5 6int g;7__attribute__((noinline))8int foo(int cond) {9 if (cond)10 return g;11 return 0;12}13 14void *Thread1(void *p) {15 barrier_wait(&barrier);16 long res = foo((long)p);17 return (void*) res;18}19 20int 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 race29 // CHECK: PASS30}31