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