1// RUN: %clangxx_msan -m64 -O0 %s -o %t && %t >%t.out 2>&1
2// RUN: %clangxx_msan -m64 -O1 %s -o %t && %t >%t.out 2>&1
3// RUN: %clangxx_msan -m64 -O2 %s -o %t && %t >%t.out 2>&1
4// RUN: %clangxx_msan -m64 -O3 %s -o %t && %t >%t.out 2>&1
5
6// RUN: %clangxx_msan -m64 -O0 %s -o %t -DCHECK_IN_F && %t >%t.out 2>&1
7// RUN: %clangxx_msan -m64 -O1 %s -o %t -DCHECK_IN_F && %t >%t.out 2>&1
8// RUN: %clangxx_msan -m64 -O2 %s -o %t -DCHECK_IN_F && %t >%t.out 2>&1
9// RUN: %clangxx_msan -m64 -O3 %s -o %t -DCHECK_IN_F && %t >%t.out 2>&1
10
11// Test that (no_sanitize_memory) functions
12// * don't check shadow values (-DCHECK_IN_F)
13// * treat all values loaded from memory as fully initialized (-UCHECK_IN_F)
14
15#include <stdlib.h>
16#include <stdio.h>
17
18__attribute__((noinline))
19__attribute__((no_sanitize_memory))
20int f(void) {
21  int x;
22  int * volatile p = &x;
23#ifdef CHECK_IN_F
24  if (*p)
25    exit(0);
26#endif
27  return *p;
28}
29
30int main(void) {
31  if (f())
32    exit(0);
33  return 0;
34}
35