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