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
6void *Thread(void *a) {
7 __atomic_store_n((int*)a, 1, __ATOMIC_RELAXED);
8 return 0;
9}
10
11int main() {
12 int *a = new int(0);
13 pthread_t t;
14 pthread_create(newthread: &t, attr: 0, start_routine: Thread, arg: a);
15 while (__atomic_load_n(a, __ATOMIC_RELAXED) == 0)
16 sched_yield();
17 delete a;
18 pthread_join(th: t, thread_return: 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 Thread
28

source code of compiler-rt/test/tsan/atomic_free3.cpp