1// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2// This test fails on powerpc64 BE (VMA=44), it does not appear to be
3// a functional problem, but the Tsan report is missing some info.
4// XFAIL: target=powerpc64-unknown-linux-gnu{{.*}}
5
6#include "test.h"
7#include <signal.h>
8#include <sys/types.h>
9#include <errno.h>
10
11pthread_t mainth;
12volatile int done;
13
14static void MyHandler(int, siginfo_t *s, void *c) {
15 errno = 1;
16 done = 1;
17}
18
19static void* sendsignal(void *p) {
20 barrier_wait(barrier: &barrier);
21 pthread_kill(threadid: mainth, SIGPROF);
22 return 0;
23}
24
25static __attribute__((noinline)) void loop() {
26 barrier_wait(barrier: &barrier);
27 while (done == 0) {
28 volatile char *p = (char*)malloc(size: 1);
29 p[0] = 0;
30 free(ptr: (void*)p);
31 sched_yield();
32 }
33}
34
35int main() {
36 barrier_init(barrier: &barrier, count: 2);
37 mainth = pthread_self();
38 struct sigaction act = {};
39 act.sa_sigaction = &MyHandler;
40 sigaction(SIGPROF, act: &act, oact: 0);
41 pthread_t th;
42 pthread_create(newthread: &th, attr: 0, start_routine: sendsignal, arg: 0);
43 loop();
44 pthread_join(th: th, thread_return: 0);
45 return 0;
46}
47
48// CHECK: WARNING: ThreadSanitizer: signal handler spoils errno
49// CHECK: Signal 27 handler invoked at:
50// CHECK: #0 MyHandler(int, {{(__)?}}siginfo{{(_t)?}}*, void*) {{.*}}signal_errno.cpp
51// CHECK: main
52// CHECK: SUMMARY: ThreadSanitizer: signal handler spoils errno{{.*}}MyHandler
53

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