Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / simple_stack2.cpp
blob5428dbcde933692b2c3b3fb0fdb6292b354c3ff0
1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2 #include "test.h"
4 int Global;
6 void __attribute__((noinline)) foo1() {
7 Global = 42;
10 void __attribute__((noinline)) bar1() {
11 volatile int tmp = 42;
12 int tmp2 = tmp;
13 (void)tmp2;
14 foo1();
17 void __attribute__((noinline)) foo2() {
18 volatile int tmp = Global;
19 int tmp2 = tmp;
20 (void)tmp2;
23 void __attribute__((noinline)) bar2() {
24 volatile int tmp = 42;
25 int tmp2 = tmp;
26 (void)tmp2;
27 foo2();
30 void *Thread1(void *x) {
31 barrier_wait(&barrier);
32 bar1();
33 return NULL;
36 int 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);
45 // CHECK: WARNING: ThreadSanitizer: data race
46 // CHECK-NEXT: Write of size 4 at {{.*}} by thread T1:
47 // CHECK-NEXT: #0 foo1{{.*}} {{.*}}simple_stack2.cpp:[[@LINE-40]]{{(:10)?}} ({{.*}})
48 // CHECK-NEXT: #1 bar1{{.*}} {{.*}}simple_stack2.cpp:[[@LINE-34]]{{(:3)?}} ({{.*}})
49 // CHECK-NEXT: #2 Thread1{{.*}} {{.*}}simple_stack2.cpp:[[@LINE-17]]{{(:3)?}} ({{.*}})
50 // CHECK: Previous read of size 4 at {{.*}} by main thread:
51 // CHECK-NEXT: #0 foo2{{.*}} {{.*}}simple_stack2.cpp:[[@LINE-33]]{{(:22)?}} ({{.*}})
52 // CHECK-NEXT: #1 bar2{{.*}} {{.*}}simple_stack2.cpp:[[@LINE-25]]{{(:3)?}} ({{.*}})
53 // CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack2.cpp:[[@LINE-13]]{{(:3)?}} ({{.*}})