]> git.proxmox.com Git - rustc.git/blame - src/compiler-rt/test/tsan/inlined_memcpy_race2.cc
New upstream version 1.12.0+dfsg1
[rustc.git] / src / compiler-rt / test / tsan / inlined_memcpy_race2.cc
CommitLineData
5bcae85e 1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
92a42be0
SL
2#include "test.h"
3#include <string.h>
4
5int y[4], z[4];
6
7void *MemMoveThread(void *a) {
8 memmove((int*)a, z, 16);
9 barrier_wait(&barrier);
10 return NULL;
11}
12
13void *MemSetThread(void *a) {
14 barrier_wait(&barrier);
15 memset((int*)a, 0, 16);
16 return NULL;
17}
18
19int main() {
20 barrier_init(&barrier, 2);
21 pthread_t t[2];
22 // Race on y between memmove and memset
23 pthread_create(&t[0], NULL, MemMoveThread, y);
24 pthread_create(&t[1], NULL, MemSetThread, y);
25 pthread_join(t[0], NULL);
26 pthread_join(t[1], NULL);
27
5bcae85e 28 fprintf(stderr, "PASS\n");
92a42be0
SL
29 return 0;
30}
31
32// CHECK: WARNING: ThreadSanitizer: data race
33// CHECK: #0 memset
34// CHECK: #1 MemSetThread
35// CHECK: Previous write
5bcae85e 36// CHECK: #0 {{(memcpy|memmove)}}
92a42be0 37// CHECK: #1 MemMoveThread