Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / msan / Linux / signal_mcontext.cpp
blobb49451fbb730b6475d9884607df030bd26baafb1
1 // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
3 #include <pthread.h>
4 #include <sanitizer/msan_interface.h>
5 #include <signal.h>
6 #include <stdint.h>
7 #include <stdio.h>
8 #include <ucontext.h>
9 #include <unistd.h>
11 void handler(int sig, siginfo_t *info, void *uctx) {
12 __msan_check_mem_is_initialized(uctx, sizeof(ucontext_t));
13 #if defined(__GLIBC__) && defined(__x86_64__)
14 auto *mctx = &static_cast<ucontext_t *>(uctx)->uc_mcontext;
15 if (auto *fpregs = mctx->fpregs) {
16 // The member names differ across header versions, but the actual layout
17 // is always the same. So avoid using members, just use arithmetic.
18 const uint32_t *after_xmm =
19 reinterpret_cast<const uint32_t *>(fpregs + 1) - 24;
20 if (after_xmm[12] == FP_XSTATE_MAGIC1) {
21 auto *xstate = reinterpret_cast<_xstate *>(mctx->fpregs);
22 __msan_check_mem_is_initialized(xstate, sizeof(*xstate));
25 #endif
28 __attribute__((noinline)) void poison_stack() {
29 char buf[64 << 10];
30 printf("buf: %p-%p\n", buf, buf + sizeof(buf));
33 int main(int argc, char **argv) {
34 struct sigaction act = {};
35 act.sa_sigaction = handler;
36 act.sa_flags = SA_SIGINFO;
37 sigaction(SIGPROF, &act, 0);
38 poison_stack();
39 pthread_kill(pthread_self(), SIGPROF);
40 return 0;
43 // CHECK-NOT: WARNING: MemorySanitizer: