1// RUN: %clangxx_tsan -O1 -DTEST_ERROR=ERANGE %s -o %t && %run %t 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-SYS %s
2// RUN: %clangxx_tsan -O1 -DTEST_ERROR=-1 %s -o %t && not %run %t 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-USER %s
3// This test is for GNU specific version of strerror_r()
4// UNSUPPORTED: darwin, target={{.*(netbsd|freebsd).*}}
5
6#include "test.h"
7
8#include <errno.h>
9#include <pthread.h>
10#include <string.h>
11
12char buffer[1000];
13
14void *Thread(void *p) {
15 barrier_wait(barrier: &barrier);
16 return strerror_r(TEST_ERROR, buffer, sizeof(buffer));
17}
18
19int main() {
20 barrier_init(barrier: &barrier, count: 2);
21 pthread_t th;
22 pthread_create(newthread: &th, attr: 0, start_routine: Thread, arg: 0);
23 strerror_r(TEST_ERROR, buffer, sizeof(buffer));
24 barrier_wait(barrier: &barrier);
25 pthread_join(th: th, thread_return: 0);
26 fprintf(stderr, format: "DONE\n");
27}
28
29// CHECK-USER: WARNING: ThreadSanitizer: data race
30// CHECK-SYS-NOT: WARNING: ThreadSanitizer: data race
31
32// CHECK: DONE
33

source code of compiler-rt/test/tsan/strerror_r.cpp