Home | History | Annotate | Download | only in tsan
      1 // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
      2 #include "test.h"
      3 #include <signal.h>
      4 #include <sys/types.h>
      5 
      6 static void handler(int, siginfo_t*, void*) {
      7   // CHECK: WARNING: ThreadSanitizer: signal-unsafe call inside of a signal
      8   // CHECK:     #0 malloc
      9   // CHECK:     #{{(1|2)}} handler(int, {{(__)?}}siginfo{{(_t)?}}*, void*) {{.*}}signal_malloc.cc:[[@LINE+2]]
     10   // CHECK: SUMMARY: ThreadSanitizer: signal-unsafe call inside of a signal{{.*}}handler
     11   volatile char *p = (char*)malloc(1);
     12   p[0] = 0;
     13   free((void*)p);
     14 }
     15 
     16 int main() {
     17   struct sigaction act = {};
     18   act.sa_sigaction = &handler;
     19   sigaction(SIGPROF, &act, 0);
     20   kill(getpid(), SIGPROF);
     21   sleep(1);  // let the signal handler run
     22   return 0;
     23 }
     24 
     25