]> git.proxmox.com Git - rustc.git/blame - src/compiler-rt/test/tsan/Linux/user_fopen.cc
Imported Upstream version 1.6.0+dfsg1
[rustc.git] / src / compiler-rt / test / tsan / Linux / user_fopen.cc
CommitLineData
1a4d82fc
JJ
1// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2#include <stdio.h>
3#include <stdlib.h>
4
92a42be0 5// Defined by tsan.
1a4d82fc
JJ
6extern "C" FILE *__interceptor_fopen(const char *file, const char *mode);
7extern "C" int __interceptor_fileno(FILE *f);
8
9extern "C" FILE *fopen(const char *file, const char *mode) {
10 static int first = 0;
11 if (__sync_lock_test_and_set(&first, 1) == 0)
12 printf("user fopen\n");
13 return __interceptor_fopen(file, mode);
14}
15
16extern "C" int fileno(FILE *f) {
17 static int first = 0;
18 if (__sync_lock_test_and_set(&first, 1) == 0)
19 printf("user fileno\n");
20 return 1;
21}
22
23int main() {
24 FILE *f = fopen("/dev/zero", "r");
25 if (f) {
26 char buf;
27 fread(&buf, 1, 1, f);
28 fclose(f);
29 }
30}
31
32// CHECK: user fopen
33// CHECK-NOT: ThreadSanitizer
34