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