Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / msan / Linux / signal_mcontext2.cpp
blobf65f909c87ef18056f1c35cff34d219fc6acfff1
1 // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
3 // musl does not define FP_XSTATE_MAGIC1.
4 // REQUIRES: x86_64-target-arch && glibc-2.27
6 #include <pthread.h>
7 #include <signal.h>
8 #include <stdint.h>
9 #include <ucontext.h>
11 void handler(int sig, siginfo_t *info, void *uctx) {
12 volatile int uninit;
13 auto *mctx = &static_cast<ucontext_t *>(uctx)->uc_mcontext;
14 auto *fpregs = mctx->fpregs;
15 // The member names differ across header versions, but the actual layout
16 // is always the same. So avoid using members, just use arithmetic.
17 const uint32_t *after_xmm =
18 reinterpret_cast<const uint32_t *>(fpregs + 1) - 24;
19 if (after_xmm[12] == FP_XSTATE_MAGIC1)
20 reinterpret_cast<_xstate *>(mctx->fpregs)->ymmh.ymmh_space[0] = uninit;
21 else
22 mctx->gregs[REG_RAX] = uninit;
25 int main(int argc, char **argv) {
26 struct sigaction act = {};
27 act.sa_sigaction = handler;
28 act.sa_flags = SA_SIGINFO;
29 sigfillset(&act.sa_mask);
30 sigaction(SIGPROF, &act, 0);
31 pthread_kill(pthread_self(), SIGPROF);
32 return 0;
35 // CHECK: WARNING: MemorySanitizer: