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