1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2 #include "test.h"
3 
4 // Test for https://github.com/google/sanitizers/issues/602
5 
Thread(void * a)6 void *Thread(void *a) {
7   __atomic_store_n((int*)a, 1, __ATOMIC_RELAXED);
8   return 0;
9 }
10 
main()11 int main() {
12   int *a = new int(0);
13   pthread_t t;
14   pthread_create(&t, 0, Thread, a);
15   while (__atomic_load_n(a, __ATOMIC_RELAXED) == 0)
16     sched_yield();
17   delete a;
18   pthread_join(t, 0);
19 }
20 
21 // CHECK: WARNING: ThreadSanitizer: data race
22 // CHECK:   Write
23 // CHECK:     #0 operator delete
24 // CHECK:     #1 main
25 
26 // CHECK:   Previous atomic write
27 // CHECK:     #0 __tsan_atomic32_store
28 // CHECK:     #1 Thread
29