28 lines · cpp
1// RUN: %clangxx_msan -O2 %s -o %t && %run %t2 3#include <sanitizer/msan_interface.h>4 5struct 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 into13// ((*(uint64_t *)&s) * (10000 * 2**32)) >> 3214// Test that MSan understands that this kills the uninitialized high half of S15// (i.e. S::b).16void FooRun(S s) {17 int64_t x = 10000 * s.a;18 __msan_check_mem_is_initialized(&x, sizeof(x));19}20 21int main(void) {22 S z(1);23 // Take &z to ensure that it is built on stack.24 S *volatile p = &z;25 FooRun(z);26 return 0;27}28