1 // RUN: %clangxx_msan -fno-sanitize-memory-param-retval -fno-sanitize=memory -c %s -o %t-main.o
2 // RUN: %clangxx_msan -fno-sanitize-memory-param-retval %t-main.o %s -o %t
11 #include <sanitizer/msan_interface.h>
13 #if __has_feature(memory_sanitizer)
15 __attribute__((noinline
)) int bar(int a
, int b
) {
16 volatile int zero
= 0;
20 void foo(int x
, int y
, int expected
) {
21 assert(__msan_test_shadow(&x
, sizeof(x
)) == expected
);
22 assert(__msan_test_shadow(&y
, sizeof(y
)) == expected
);
24 // Poisons parameter shadow in TLS so that the next call (to foo) from
25 // uninstrumented main has params 1 and 2 poisoned no matter what.
32 // This code is not instrumented by MemorySanitizer to prevent it from modifying
33 // MSAN TLS data for this test.
35 int foo(int, int, int);
37 int main(int argc
, char **argv
) {
39 // The parameters should _not_ be poisoned; this is the first call to foo.
41 // The parameters should be poisoned; the prior call to foo left them so.
45 if (getcontext(&ctx
) == -1) {
50 // Simulate a fiber switch occurring from MSAN's perspective (though no switch
52 const void *previous_stack_bottom
= nullptr;
53 size_t previous_stack_size
= 0;
54 __msan_start_switch_fiber(ctx
.uc_stack
.ss_sp
, ctx
.uc_stack
.ss_size
);
55 __msan_finish_switch_fiber(&previous_stack_bottom
, &previous_stack_size
);
57 // The simulated fiber switch will reset the TLS parameter shadow. So even
58 // though the most recent call to foo left the parameter shadow poisoned, the
59 // parameters are _not_ expected to be poisoned now.