Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / fd_location_closed.cpp
blobbde0487d27057c3fbd50a001e366ba729be37c1c
1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2 #include "test.h"
4 #include <fcntl.h>
6 void *Thread(void *x) {
7 int fd = (long)x;
8 char buf;
9 read(fd, &buf, 1);
10 barrier_wait(&barrier);
11 close(fd);
12 return NULL;
15 int main() {
16 barrier_init(&barrier, 2);
17 int fd = open("/dev/random", O_RDONLY);
18 pthread_t t[2];
19 pthread_create(&t[0], NULL, Thread, (void *)(long)fd);
20 pthread_create(&t[1], NULL, Thread, (void *)(long)fd);
22 pthread_join(t[0], NULL);
23 pthread_join(t[1], NULL);
26 // CHECK: WARNING: ThreadSanitizer: data race
27 // CHECK: Location is file descriptor {{[0-9]+}} {{(destroyed by thread|created by main)}}
28 // CHECK: #0 {{close|open}}
29 // CHECK: #1 {{Thread|main}}