1 | // RUN: %clangxx_msan -O2 %s -o %t && %run %t |
2 | |
3 | #include <sanitizer/msan_interface.h> |
4 | |
5 | struct S { |
6 | S(int a0) : a(a0) {} |
7 | int a; |
8 | int b; |
9 | }; |
10 | |
11 | // Here S is passed to FooRun as a 64-bit integer. |
12 | // This triggers an optimization where 10000 * s.a is transformed into |
13 | // ((*(uint64_t *)&s) * (10000 * 2**32)) >> 32 |
14 | // Test that MSan understands that this kills the uninitialized high half of S |
15 | // (i.e. S::b). |
16 | void FooRun(S s) { |
17 | int64_t x = 10000 * s.a; |
18 | __msan_check_mem_is_initialized(x: &x, size: sizeof(x)); |
19 | } |
20 | |
21 | int main(void) { |
22 | S z(1); |
23 | // Take &z to ensure that it is built on stack. |
24 | S *volatile p = &z; |
25 | FooRun(s: z); |
26 | return 0; |
27 | } |
28 | |