2014-11-19 18:47:06 +08:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %T/simple_stack2.cc.exe && %deflake %run %T/simple_stack2.cc.exe | FileCheck %s
|
2015-01-21 21:50:02 +08:00
|
|
|
#include "test.h"
|
2012-05-10 22:18:22 +08:00
|
|
|
|
|
|
|
int Global;
|
|
|
|
|
|
|
|
void __attribute__((noinline)) foo1() {
|
|
|
|
Global = 42;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __attribute__((noinline)) bar1() {
|
2012-08-30 22:22:21 +08:00
|
|
|
volatile int tmp = 42;
|
|
|
|
int tmp2 = tmp;
|
|
|
|
(void)tmp2;
|
2012-05-10 22:18:22 +08:00
|
|
|
foo1();
|
|
|
|
}
|
|
|
|
|
|
|
|
void __attribute__((noinline)) foo2() {
|
2012-08-30 22:22:21 +08:00
|
|
|
volatile int tmp = Global;
|
|
|
|
int tmp2 = tmp;
|
|
|
|
(void)tmp2;
|
2012-05-10 22:18:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void __attribute__((noinline)) bar2() {
|
2012-08-30 22:22:21 +08:00
|
|
|
volatile int tmp = 42;
|
|
|
|
int tmp2 = tmp;
|
|
|
|
(void)tmp2;
|
2012-05-10 22:18:22 +08:00
|
|
|
foo2();
|
|
|
|
}
|
|
|
|
|
|
|
|
void *Thread1(void *x) {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2012-05-10 22:18:22 +08:00
|
|
|
bar1();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_init(&barrier, 2);
|
2012-05-10 22:18:22 +08:00
|
|
|
pthread_t t;
|
|
|
|
pthread_create(&t, NULL, Thread1, NULL);
|
|
|
|
bar2();
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2012-05-10 22:18:22 +08:00
|
|
|
pthread_join(t, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: WARNING: ThreadSanitizer: data race
|
2012-12-06 20:16:15 +08:00
|
|
|
// CHECK-NEXT: Write of size 4 at {{.*}} by thread T1:
|
2015-01-25 12:39:06 +08:00
|
|
|
// CHECK-NEXT: #0 foo1{{.*}} {{.*}}simple_stack2.cc:7{{(:10)?}} (simple_stack2.cc.exe+{{.*}})
|
2015-01-21 21:50:02 +08:00
|
|
|
// CHECK-NEXT: #1 bar1{{.*}} {{.*}}simple_stack2.cc:14{{(:3)?}} (simple_stack2.cc.exe+{{.*}})
|
|
|
|
// CHECK-NEXT: #2 Thread1{{.*}} {{.*}}simple_stack2.cc:32{{(:3)?}} (simple_stack2.cc.exe+{{.*}})
|
2012-08-30 21:02:30 +08:00
|
|
|
// CHECK: Previous read of size 4 at {{.*}} by main thread:
|
2015-01-21 21:50:02 +08:00
|
|
|
// CHECK-NEXT: #0 foo2{{.*}} {{.*}}simple_stack2.cc:18{{(:22)?}} (simple_stack2.cc.exe+{{.*}})
|
|
|
|
// CHECK-NEXT: #1 bar2{{.*}} {{.*}}simple_stack2.cc:27{{(:3)?}} (simple_stack2.cc.exe+{{.*}})
|
|
|
|
// CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack2.cc:40{{(:3)?}} (simple_stack2.cc.exe+{{.*}})
|