1 // RUN: %clangxx_tsan -O1 %s -o %T/simple_stack2.cc.exe && %deflake %run %T/simple_stack2.cc.exe | FileCheck %s 2 #include "test.h" 3 4 int Global; 5 foo1()6void __attribute__((noinline)) foo1() { 7 Global = 42; 8 } 9 bar1()10void __attribute__((noinline)) bar1() { 11 volatile int tmp = 42; 12 int tmp2 = tmp; 13 (void)tmp2; 14 foo1(); 15 } 16 foo2()17void __attribute__((noinline)) foo2() { 18 volatile int tmp = Global; 19 int tmp2 = tmp; 20 (void)tmp2; 21 } 22 bar2()23void __attribute__((noinline)) bar2() { 24 volatile int tmp = 42; 25 int tmp2 = tmp; 26 (void)tmp2; 27 foo2(); 28 } 29 Thread1(void * x)30void *Thread1(void *x) { 31 barrier_wait(&barrier); 32 bar1(); 33 return NULL; 34 } 35 main()36int main() { 37 barrier_init(&barrier, 2); 38 pthread_t t; 39 pthread_create(&t, NULL, Thread1, NULL); 40 bar2(); 41 barrier_wait(&barrier); 42 pthread_join(t, NULL); 43 } 44 45 // CHECK: WARNING: ThreadSanitizer: data race 46 // CHECK-NEXT: Write of size 4 at {{.*}} by thread T1: 47 // CHECK-NEXT: #0 foo1{{.*}} {{.*}}simple_stack2.cc:7{{(:10)?}} (simple_stack2.cc.exe+{{.*}}) 48 // CHECK-NEXT: #1 bar1{{.*}} {{.*}}simple_stack2.cc:14{{(:3)?}} (simple_stack2.cc.exe+{{.*}}) 49 // CHECK-NEXT: #2 Thread1{{.*}} {{.*}}simple_stack2.cc:32{{(:3)?}} (simple_stack2.cc.exe+{{.*}}) 50 // CHECK: Previous read of size 4 at {{.*}} by main thread: 51 // CHECK-NEXT: #0 foo2{{.*}} {{.*}}simple_stack2.cc:18{{(:22)?}} (simple_stack2.cc.exe+{{.*}}) 52 // CHECK-NEXT: #1 bar2{{.*}} {{.*}}simple_stack2.cc:27{{(:3)?}} (simple_stack2.cc.exe+{{.*}}) 53 // CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack2.cc:40{{(:3)?}} (simple_stack2.cc.exe+{{.*}}) 54