]>
git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/tsan/simple_stack.c
1 // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
6 void __attribute__((noinline
)) foo1() {
10 void __attribute__((noinline
)) bar1() {
11 volatile int tmp
= 42; (void)tmp
;
15 void __attribute__((noinline
)) foo2() {
16 volatile int v
= Global
; (void)v
;
19 void __attribute__((noinline
)) bar2() {
20 volatile int tmp
= 42; (void)tmp
;
24 void *Thread1(void *x
) {
25 barrier_wait(&barrier
);
30 void *Thread2(void *x
) {
32 barrier_wait(&barrier
);
36 void StartThread(pthread_t
*t
, void *(*f
)(void*)) {
37 pthread_create(t
, NULL
, f
, NULL
);
41 barrier_init(&barrier
, 2);
43 StartThread(&t
[0], Thread1
);
44 StartThread(&t
[1], Thread2
);
45 pthread_join(t
[0], NULL
);
46 pthread_join(t
[1], NULL
);
50 // CHECK: WARNING: ThreadSanitizer: data race
51 // CHECK-NEXT: Write of size 4 at {{.*}} by thread T1:
52 // CHECK-NEXT: #0 foo1{{.*}} {{.*}}simple_stack.c:7{{(:10)?}} ({{.*}})
53 // CHECK-NEXT: #1 bar1{{.*}} {{.*}}simple_stack.c:12{{(:3)?}} ({{.*}})
54 // CHECK-NEXT: #2 Thread1{{.*}} {{.*}}simple_stack.c:26{{(:3)?}} ({{.*}})
55 // CHECK: Previous read of size 4 at {{.*}} by thread T2:
56 // CHECK-NEXT: #0 foo2{{.*}} {{.*}}simple_stack.c:16{{(:20)?}} ({{.*}})
57 // CHECK-NEXT: #1 bar2{{.*}} {{.*}}simple_stack.c:21{{(:3)?}} ({{.*}})
58 // CHECK-NEXT: #2 Thread2{{.*}} {{.*}}simple_stack.c:31{{(:3)?}} ({{.*}})
59 // CHECK: Thread T1 (tid={{.*}}, running) created by main thread at:
60 // CHECK-NEXT: #0 pthread_create {{.*}} ({{.*}})
61 // CHECK-NEXT: #1 StartThread{{.*}} {{.*}}simple_stack.c:37{{(:3)?}} ({{.*}})
62 // CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack.c:43{{(:3)?}} ({{.*}})
63 // CHECK: Thread T2 ({{.*}}) created by main thread at:
64 // CHECK-NEXT: #0 pthread_create {{.*}} ({{.*}})
65 // CHECK-NEXT: #1 StartThread{{.*}} {{.*}}simple_stack.c:37{{(:3)?}} ({{.*}})
66 // CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack.c:44{{(:3)?}} ({{.*}})