Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / dfsan / origin_with_sigactions.c
blob95395ba9e23e09e5099814f7e09632453848d55b
1 // Check that stores in signal handlers are not recorded in origin history.
2 //
3 // Origin tracking uses ChainedOriginDepot that is not async signal safe, so we
4 // do not track origins inside signal handlers.
5 //
6 // RUN: %clang_dfsan -gmlt -DUSE_SIGNAL_ACTION -mllvm -dfsan-track-origins=1 %s -o %t && \
7 // RUN: %run %t >%t.out 2>&1
8 // RUN: FileCheck %s < %t.out
9 //
10 // RUN: %clang_dfsan -gmlt -DUSE_SIGNAL_ACTION -mllvm -dfsan-instrument-with-call-threshold=0 -mllvm -dfsan-track-origins=1 %s -o %t && \
11 // RUN: %run %t >%t.out 2>&1
12 // RUN: FileCheck %s < %t.out
14 // RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 %s -o %t && \
15 // RUN: %run %t >%t.out 2>&1
16 // RUN: FileCheck %s < %t.out
18 // RUN: %clang_dfsan -gmlt -mllvm -dfsan-instrument-with-call-threshold=0 -mllvm -dfsan-track-origins=1 %s -o %t && \
19 // RUN: %run %t >%t.out 2>&1
20 // RUN: FileCheck %s < %t.out
22 #include <sanitizer/dfsan_interface.h>
24 #include <assert.h>
25 #include <signal.h>
26 #include <string.h>
27 #include <sys/types.h>
28 #include <unistd.h>
30 int x, y, u;
32 void CopyXtoYtoU() {
33 y = x;
34 memcpy(&u, &y, sizeof(int));
37 void SignalHandler(int signo) {
38 CopyXtoYtoU();
41 void SignalAction(int signo, siginfo_t *si, void *uc) {
42 CopyXtoYtoU();
45 int main(int argc, char *argv[]) {
46 int z = 1;
47 dfsan_set_label(8, &z, sizeof(z));
48 x = z;
50 struct sigaction psa = {};
51 #ifdef USE_SIGNAL_ACTION
52 psa.sa_flags = SA_SIGINFO;
53 psa.sa_sigaction = SignalAction;
54 #else
55 psa.sa_flags = 0;
56 psa.sa_handler = SignalHandler;
57 #endif
58 sigaction(SIGHUP, &psa, NULL);
59 kill(getpid(), SIGHUP);
60 signal(SIGHUP, SIG_DFL);
62 assert(x == 1);
63 assert(y == 1);
64 assert(u == 1);
66 dfsan_print_origin_trace(&u, NULL);
67 return 0;
70 // CHECK: Taint value 0x8 {{.*}} origin tracking ()
71 // CHECK: Origin value: {{.*}}, Taint value was stored to memory at
72 // CHECK-NOT: {{.*}} in CopyXtoYtoU.dfsan {{.*}}origin_with_sigactions.c{{.*}}
74 // CHECK: #0 {{.*}} in main {{.*}}origin_with_sigactions.c:[[@LINE-26]]
76 // CHECK: Origin value: {{.*}}, Taint value was created at
77 // CHECK: #0 {{.*}} in main {{.*}}origin_with_sigactions.c:[[@LINE-30]]