1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2#include "test.h"
3
4volatile long X;
5volatile long Y;
6volatile int N1 = 2 << 10;
7volatile int N2 = 32 << 10;
8void (*volatile F)();
9void (*volatile G)();
10
11static void foo() {
12 if (--N1)
13 return F();
14 while (--N2)
15 G();
16}
17
18static void bar() { Y++; }
19
20void *Thread(void *p) {
21 F();
22 X = 43;
23 barrier_wait(barrier: &barrier);
24 return 0;
25}
26
27int main() {
28 barrier_init(barrier: &barrier, count: 2);
29 F = foo;
30 G = bar;
31 pthread_t t;
32 pthread_create(newthread: &t, attr: 0, start_routine: Thread, arg: 0);
33 barrier_wait(barrier: &barrier);
34 X = 43;
35 pthread_join(th: t, thread_return: 0);
36}
37
38// CHECK: WARNING: ThreadSanitizer: data race
39// CHECK: Write
40// CHECK: #0 main
41// CHECK: Previous write
42// CHECK: #0 Thread
43

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