Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / dfsan / sigaction.c
blob5b22d06a8d565927b5085e7e374e5449e0e03f0e
1 // RUN: %clang_dfsan -DUSE_SIGNAL_ACTION -Wno-error=int-conversion %s -o %t && %run %t
2 // RUN: %clang_dfsan -Wno-error=int-conversion %s -o %t && %run %t
4 #include <sanitizer/dfsan_interface.h>
6 #include <assert.h>
7 #include <signal.h>
8 #include <string.h>
9 #include <sys/types.h>
10 #include <unistd.h>
12 volatile int x;
13 volatile int z = 1;
15 void SignalHandler(int signo) {
16 assert(dfsan_get_label(signo) == 0);
17 x = z;
20 void SignalAction(int signo, siginfo_t *si, void *uc) {
21 assert(dfsan_get_label(signo) == 0);
22 assert(dfsan_get_label(si) == 0);
23 assert(dfsan_get_label(uc) == 0);
24 assert(0 == dfsan_read_label(si, sizeof(*si)));
25 assert(0 == dfsan_read_label(uc, sizeof(ucontext_t)));
26 x = z;
29 int main(int argc, char *argv[]) {
30 dfsan_set_label(8, (void *)&z, sizeof(z));
32 struct sigaction sa = {};
33 #ifdef USE_SIGNAL_ACTION
34 sa.sa_flags = SA_SIGINFO;
35 sa.sa_sigaction = SignalAction;
36 #else
37 sa.sa_handler = SignalHandler;
38 #endif
39 int r = sigaction(SIGHUP, &sa, NULL);
40 assert(dfsan_get_label(r) == 0);
42 kill(getpid(), SIGHUP);
43 signal(SIGHUP, SIG_DFL);
45 assert(x == 1);
47 return 0;