Home | History | Annotate | Download | only in lit_tests
      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>
      9 
     10 pthread_t mainth;
     11 volatile int done;
     12 
     13 static void MyHandler(int, siginfo_t *s, void *c) {
     14   errno = 1;
     15   done = 1;
     16 }
     17 
     18 static void* sendsignal(void *p) {
     19   pthread_kill(mainth, SIGPROF);
     20   return 0;
     21 }
     22 
     23 int main() {
     24   mainth = pthread_self();
     25   struct sigaction act = {};
     26   act.sa_sigaction = &MyHandler;
     27   sigaction(SIGPROF, &act, 0);
     28   pthread_t th;
     29   pthread_create(&th, 0, sendsignal, 0);
     30   while (done == 0) {
     31     volatile char *p = (char*)malloc(1);
     32     p[0] = 0;
     33     free((void*)p);
     34     pthread_yield();
     35   }
     36   pthread_join(th, 0);
     37   return 0;
     38 }
     39 
     40 // CHECK: WARNING: ThreadSanitizer: signal handler spoils errno
     41 // CHECK:     #0 MyHandler(int, siginfo{{(_t)?}}*, void*) {{.*}}signal_errno.cc
     42 // CHECK: SUMMARY: ThreadSanitizer: signal handler spoils errno{{.*}}MyHandler
     43 
     44