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