| 1 | // RUN: %clangxx_msan -O0 %s -o %t && %run %t >%t.out 2>&1 |
| 2 | // RUN: %clangxx_msan -O1 %s -o %t && %run %t >%t.out 2>&1 |
| 3 | // RUN: %clangxx_msan -O2 %s -o %t && %run %t >%t.out 2>&1 |
| 4 | // RUN: %clangxx_msan -O3 %s -o %t && %run %t >%t.out 2>&1 |
| 5 | |
| 6 | // RUN: %clangxx_msan -O0 %s -o %t -DCHECK_IN_F && %run %t >%t.out 2>&1 |
| 7 | // RUN: %clangxx_msan -O1 %s -o %t -DCHECK_IN_F && %run %t >%t.out 2>&1 |
| 8 | // RUN: %clangxx_msan -O2 %s -o %t -DCHECK_IN_F && %run %t >%t.out 2>&1 |
| 9 | // RUN: %clangxx_msan -O3 %s -o %t -DCHECK_IN_F && %run %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)) |
| 20 | int 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 | |
| 30 | int main(void) { |
| 31 | if (f()) |
| 32 | exit(status: 0); |
| 33 | return 0; |
| 34 | } |
| 35 | |