Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / signal_thread2.cpp
blob9bde4f70b39d81663c048bb08064a047fd8ee345
1 // RUN: %clangxx_tsan %s -o %t && %run %t 2>&1 | FileCheck %s
2 // UNSUPPORTED: darwin
4 // It's very flaky on PPC with COMPILER_RT_DEBUG.
5 // UNSUPPORTED: !compiler-rt-optimized && ppc
7 // Test case for https://github.com/google/sanitizers/issues/1540
9 #include <errno.h>
10 #include <pthread.h>
11 #include <signal.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <sys/time.h>
15 #include <sys/types.h>
16 #include <unistd.h>
18 volatile int X;
20 static void handler(int sig) {
21 (void)sig;
22 if (X != 0)
23 printf("bad");
26 static void *thr1(void *p) {
27 sleep(1);
28 return 0;
31 static void *thr(void *p) {
32 pthread_t th[10];
33 for (int i = 0; i < sizeof(th) / sizeof(th[0]); i++)
34 pthread_create(&th[i], 0, thr1, 0);
35 for (int i = 0; i < sizeof(th) / sizeof(th[0]); i++)
36 pthread_join(th[i], 0);
37 return 0;
40 int main() {
41 struct sigaction act = {};
42 act.sa_handler = &handler;
43 if (sigaction(SIGPROF, &act, 0)) {
44 perror("sigaction");
45 exit(1);
48 itimerval t;
49 t.it_value.tv_sec = 0;
50 t.it_value.tv_usec = 10;
51 t.it_interval = t.it_value;
52 if (setitimer(ITIMER_PROF, &t, 0)) {
53 perror("setitimer");
54 exit(1);
57 pthread_t th[100];
58 for (int i = 0; i < sizeof(th) / sizeof(th[0]); i++)
59 pthread_create(&th[i], 0, thr, 0);
60 for (int i = 0; i < sizeof(th) / sizeof(th[0]); i++)
61 pthread_join(th[i], 0);
63 fprintf(stderr, "DONE\n");
64 return 0;
67 // CHECK-NOT: WARNING: ThreadSanitizer:
68 // CHECK: DONE
69 // CHECK-NOT: WARNING: ThreadSanitizer: