[SLP]Reduce number of alternate instruction, where possible
[llvm-project.git] / compiler-rt / test / tsan / Linux / syscall.cpp
blob6b46bda483b1c29ca7bde28b5c5484ac0fc64540
1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
2 #include "syscall.h"
3 #include "../test.h"
4 #include <errno.h>
5 #include <sys/types.h>
6 #include <sys/wait.h>
8 int pipefd[2];
9 unsigned long long buf[2];
11 static void *thr(void *p) {
12 barrier_wait(&barrier);
13 mywrite(pipefd[1], buf, sizeof(buf));
14 return 0;
17 int main() {
18 barrier_init(&barrier, 2);
19 if (mypipe(pipefd))
20 exit((perror("pipe"), 1));
21 mywrite(pipefd[1], buf, sizeof(buf));
22 pthread_t th;
23 pthread_create(&th, 0, thr, 0);
24 myread(pipefd[0], buf, sizeof(buf));
25 barrier_wait(&barrier);
26 pthread_join(th, 0);
27 fprintf(stderr, "DONE\n");
30 // CHECK: WARNING: ThreadSanitizer: data race
31 // CHECK: Read of size 8
32 // CHECK: #0 mywrite
33 // CHECK: #1 thr
34 // CHECK: Previous write of size 8
35 // CHECK: #0 myread
36 // CHECK: #1 main
37 // CHECK: DONE