2016-04-15 20:34:00 +08:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
|
2015-11-30 22:11:48 +08:00
|
|
|
// Regtest for https://github.com/google/sanitizers/issues/447
|
2013-11-21 15:31:12 +08:00
|
|
|
// This is a correct program and tsan should not report a race.
|
2015-01-21 21:50:02 +08:00
|
|
|
#include "test.h"
|
|
|
|
|
2013-11-21 15:31:12 +08:00
|
|
|
int g;
|
|
|
|
__attribute__((noinline))
|
|
|
|
int foo(int cond) {
|
|
|
|
if (cond)
|
|
|
|
return g;
|
|
|
|
return 0;
|
|
|
|
}
|
2015-01-21 21:50:02 +08:00
|
|
|
|
2013-11-21 15:31:12 +08:00
|
|
|
void *Thread1(void *p) {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2013-11-21 15:31:12 +08:00
|
|
|
long res = foo((long)p);
|
|
|
|
return (void*) res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_init(&barrier, 2);
|
2013-11-21 15:31:12 +08:00
|
|
|
pthread_t t;
|
|
|
|
pthread_create(&t, 0, Thread1, 0);
|
|
|
|
g = 1;
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2013-11-21 15:31:12 +08:00
|
|
|
pthread_join(t, 0);
|
2016-04-15 20:34:00 +08:00
|
|
|
fprintf(stderr, "PASS\n");
|
2015-01-21 21:50:02 +08:00
|
|
|
// CHECK-NOT: ThreadSanitizer: data race
|
2013-11-21 17:09:47 +08:00
|
|
|
// CHECK: PASS
|
2013-11-21 15:31:12 +08:00
|
|
|
}
|