]>
Commit | Line | Data |
---|---|---|
92a42be0 SL |
1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s |
2 | #include "test.h" | |
1a4d82fc | 3 | #include <string.h> |
1a4d82fc | 4 | |
92a42be0 | 5 | int x[4], z[4]; |
1a4d82fc JJ |
6 | |
7 | void *MemCpyThread(void *a) { | |
8 | memcpy((int*)a, z, 16); | |
92a42be0 | 9 | barrier_wait(&barrier); |
1a4d82fc JJ |
10 | return NULL; |
11 | } | |
12 | ||
13 | void *MemSetThread(void *a) { | |
92a42be0 | 14 | barrier_wait(&barrier); |
1a4d82fc JJ |
15 | memset((int*)a, 0, 16); |
16 | return NULL; | |
17 | } | |
18 | ||
19 | int main() { | |
92a42be0 | 20 | barrier_init(&barrier, 2); |
1a4d82fc JJ |
21 | pthread_t t[2]; |
22 | // Race on x between memcpy and memset | |
23 | pthread_create(&t[0], NULL, MemCpyThread, x); | |
24 | pthread_create(&t[1], NULL, MemSetThread, x); | |
25 | pthread_join(t[0], NULL); | |
26 | pthread_join(t[1], NULL); | |
1a4d82fc JJ |
27 | printf("PASS\n"); |
28 | return 0; | |
29 | } | |
30 | ||
31 | // CHECK: WARNING: ThreadSanitizer: data race | |
32 | // CHECK: #0 memset | |
33 | // CHECK: #1 MemSetThread | |
34 | // CHECK: Previous write | |
35 | // CHECK: #0 memcpy | |
36 | // CHECK: #1 MemCpyThread | |
37 |