]>
Commit | Line | Data |
---|---|---|
92a42be0 SL |
1 | // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s |
2 | #include "test.h" | |
1a4d82fc JJ |
3 | #include <signal.h> |
4 | #include <sys/types.h> | |
1a4d82fc JJ |
5 | #include <errno.h> |
6 | ||
7 | pthread_t mainth; | |
8 | volatile int done; | |
9 | ||
10 | static void MyHandler(int, siginfo_t *s, void *c) { | |
11 | errno = 1; | |
12 | done = 1; | |
13 | } | |
14 | ||
15 | static void* sendsignal(void *p) { | |
92a42be0 | 16 | barrier_wait(&barrier); |
1a4d82fc JJ |
17 | pthread_kill(mainth, SIGPROF); |
18 | return 0; | |
19 | } | |
20 | ||
21 | static __attribute__((noinline)) void loop() { | |
92a42be0 | 22 | barrier_wait(&barrier); |
1a4d82fc JJ |
23 | while (done == 0) { |
24 | volatile char *p = (char*)malloc(1); | |
25 | p[0] = 0; | |
26 | free((void*)p); | |
92a42be0 | 27 | sched_yield(); |
1a4d82fc JJ |
28 | } |
29 | } | |
30 | ||
31 | int main() { | |
92a42be0 | 32 | barrier_init(&barrier, 2); |
1a4d82fc JJ |
33 | mainth = pthread_self(); |
34 | struct sigaction act = {}; | |
35 | act.sa_sigaction = &MyHandler; | |
36 | sigaction(SIGPROF, &act, 0); | |
37 | pthread_t th; | |
38 | pthread_create(&th, 0, sendsignal, 0); | |
39 | loop(); | |
40 | pthread_join(th, 0); | |
41 | return 0; | |
42 | } | |
43 | ||
44 | // CHECK: WARNING: ThreadSanitizer: signal handler spoils errno | |
92a42be0 | 45 | // CHECK: #0 MyHandler(int, {{(__)?}}siginfo{{(_t)?}}*, void*) {{.*}}signal_errno.cc |
1a4d82fc JJ |
46 | // CHECK: main |
47 | // CHECK: SUMMARY: ThreadSanitizer: signal handler spoils errno{{.*}}MyHandler | |
48 |