1// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2
3#include "test.h"
4
5int *mem;
6
7void *Thread(void *x) {
8 mem[0] = 42;
9 barrier_wait(barrier: &barrier);
10 return NULL;
11}
12
13int main() {
14 barrier_init(barrier: &barrier, count: 2);
15 mem = (int*)malloc(size: 100);
16 pthread_t t;
17 pthread_create(newthread: &t, attr: 0, start_routine: Thread, arg: 0);
18 barrier_wait(barrier: &barrier);
19 free(ptr: mem);
20 pthread_join(th: t, NULL);
21 return 0;
22}
23
24// CHECK: WARNING: ThreadSanitizer: data race
25// CHECK: Write of size 8 at {{.*}} by main thread{{.*}}:
26// CHECK: #0 free
27// CHECK: #{{(1|2)}} main
28// CHECK: Previous write of size 4 at {{.*}} by thread T1{{.*}}:
29// CHECK: #0 Thread
30

source code of compiler-rt/test/tsan/free_race3.c