1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s |
2 | #include "test.h" |
3 | #include <string.h> |
4 | |
5 | char *data0 = new char[10]; |
6 | char *data1 = new char[10]; |
7 | char *data2 = new char[10]; |
8 | |
9 | void *Thread1(void *x) { |
10 | static volatile int size = 1; |
11 | static volatile int sink; |
12 | sink = memcmp(s1: data0+5, s2: data1, n: size); |
13 | barrier_wait(barrier: &barrier); |
14 | return NULL; |
15 | } |
16 | |
17 | void *Thread2(void *x) { |
18 | static volatile int size = 4; |
19 | barrier_wait(barrier: &barrier); |
20 | memcpy(dest: data0+5, src: data2, n: size); |
21 | return NULL; |
22 | } |
23 | |
24 | int main() { |
25 | barrier_init(barrier: &barrier, count: 2); |
26 | print_address("addr=" , 1, &data0[5]); |
27 | pthread_t t[2]; |
28 | pthread_create(newthread: &t[0], NULL, start_routine: Thread1, NULL); |
29 | pthread_create(newthread: &t[1], NULL, start_routine: Thread2, NULL); |
30 | pthread_join(th: t[0], NULL); |
31 | pthread_join(th: t[1], NULL); |
32 | return 0; |
33 | } |
34 | |
35 | // CHECK: addr=[[ADDR:0x[0-9,a-f]+]] |
36 | // CHECK: WARNING: ThreadSanitizer: data race |
37 | // CHECK: Write of size 3 at [[ADDR]] by thread T2: |
38 | // CHECK: #0 {{.*mem(cpy|move)}} |
39 | // CHECK: #{{[12]}} Thread2 |
40 | // CHECK: Previous read of size 1 at [[ADDR]] by thread T1: |
41 | // CHECK: #0 {{.*}}memcmp |
42 | // CHECK: #{{[12]}} Thread1 |
43 | |