[Sanitizer] Add rudimentary support for wide-character strings to scanf/printf interc...
[blocksruntime.git] / test / tsan / signal_errno.cc
blob51e4d855dc0e5c8f65d4f2e23afa6e0c4371451d
1 // RUN: %clang_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s
2 #include <pthread.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <signal.h>
6 #include <sys/types.h>
7 #include <unistd.h>
8 #include <errno.h>
10 pthread_t mainth;
11 volatile int done;
13 static void MyHandler(int, siginfo_t *s, void *c) {
14 errno = 1;
15 done = 1;
18 static void* sendsignal(void *p) {
19 sleep(1);
20 pthread_kill(mainth, SIGPROF);
21 return 0;
24 static __attribute__((noinline)) void loop() {
25 while (done == 0) {
26 volatile char *p = (char*)malloc(1);
27 p[0] = 0;
28 free((void*)p);
29 pthread_yield();
33 int main() {
34 mainth = pthread_self();
35 struct sigaction act = {};
36 act.sa_sigaction = &MyHandler;
37 sigaction(SIGPROF, &act, 0);
38 pthread_t th;
39 pthread_create(&th, 0, sendsignal, 0);
40 loop();
41 pthread_join(th, 0);
42 return 0;
45 // CHECK: WARNING: ThreadSanitizer: signal handler spoils errno
46 // CHECK: #0 MyHandler(int, siginfo{{(_t)?}}*, void*) {{.*}}signal_errno.cc
47 // CHECK: main
48 // CHECK: SUMMARY: ThreadSanitizer: signal handler spoils errno{{.*}}MyHandler