1 // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
4 #include <sanitizer/msan_interface.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
));
28 __attribute__((noinline
)) void poison_stack() {
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);
39 pthread_kill(pthread_self(), SIGPROF
);
43 // CHECK-NOT: WARNING: MemorySanitizer: