Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / dfsan / origin_with_signals.cpp
blob22ea43990abb864e28281f5e3f24bc8b4f7bb184
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: %clangxx_dfsan -gmlt -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: %clangxx_dfsan -gmlt -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 #include <sanitizer/dfsan_interface.h>
16 #include <signal.h>
17 #include <string.h>
18 #include <sys/types.h>
19 #include <unistd.h>
21 int x, y, u;
23 void SignalHandler(int signo) {
24 y = x;
25 memcpy(&u, &y, sizeof(int));
28 int main(int argc, char *argv[]) {
29 int z = 0;
30 dfsan_set_label(8, &z, sizeof(z));
31 x = z;
33 signal(SIGHUP, SignalHandler);
34 kill(getpid(), SIGHUP);
35 signal(SIGHUP, SIG_DFL);
37 dfsan_print_origin_trace(&u, nullptr);
38 return 0;
41 // CHECK: Taint value 0x8 {{.*}} origin tracking ()
42 // CHECK: Origin value: {{.*}}, Taint value was stored to memory at
43 // CHECK-NOT: {{.*}} in SignalHandler.dfsan {{.*}}origin_with_signals.cpp{{.*}}
45 // CHECK: #0 {{.*}} in main {{.*}}origin_with_signals.cpp:[[@LINE-14]]
47 // CHECK: Origin value: {{.*}}, Taint value was created at
48 // CHECK: #0 {{.*}} in main {{.*}}origin_with_signals.cpp:[[@LINE-18]]