Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / static_init2.cpp
blobca2300ae6801e4c62dc3841c87ba2992233f211f
1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 #include <pthread.h>
3 #include <stdlib.h>
4 #include <stdio.h>
6 struct Cache {
7 int x;
8 explicit Cache(int x)
9 : x(x) {
13 void foo(Cache *my) {
14 static Cache *c = my ? my : new Cache(rand());
15 if (c->x >= RAND_MAX)
16 exit(1);
19 void *Thread(void *x) {
20 foo(new Cache(rand()));
21 return 0;
24 int main() {
25 pthread_t t[2];
26 pthread_create(&t[0], 0, Thread, 0);
27 pthread_create(&t[1], 0, Thread, 0);
28 pthread_join(t[0], 0);
29 pthread_join(t[1], 0);
30 fprintf(stderr, "PASS\n");
33 // CHECK-NOT: WARNING: ThreadSanitizer: data race