|
| 1 | +// Try parameter '0' (program runs cleanly) |
| 2 | +// ------------------------------------------------------- |
| 3 | +// RUN: %clangxx_msan -g %s -o %t && %run %t 0 |
| 4 | + |
| 5 | +// Try parameter '1' |
| 6 | +// ------------------------------------------------------- |
| 7 | +// RUN: %clangxx_msan -g %s -o %t && not %run %t 1 >%t.out 2>&1 |
| 8 | +// RUN: FileCheck --check-prefix STORE-CHECK %s < %t.out |
| 9 | + |
| 10 | +// RUN: %clangxx_msan -mllvm -msan-print-faulting-instruction=1 -g %s -o %t && not %run %t 1 >%t.out 2>&1 |
| 11 | +// RUN: FileCheck --check-prefixes VERBOSE-STORE-CHECK,STORE-CHECK %s < %t.out |
| 12 | + |
| 13 | +// RUN: %clangxx_msan -mllvm -msan-print-faulting-instruction=2 -g %s -o %t && not %run %t 1 >%t.out 2>&1 |
| 14 | +// RUN: FileCheck --check-prefixes VERY-VERBOSE-STORE-CHECK,STORE-CHECK %s < %t.out |
| 15 | + |
| 16 | +// Try parameter '2', with -fsanitize-memory-param-retval |
| 17 | +// ------------------------------------------------------- |
| 18 | +// RUN: %clangxx_msan -fsanitize-memory-param-retval -g %s -o %t && not %run %t 2 >%t.out 2>&1 |
| 19 | +// RUN: FileCheck --check-prefix PARAM-CHECK %s < %t.out |
| 20 | + |
| 21 | +// RUN: %clangxx_msan -fsanitize-memory-param-retval -mllvm -msan-print-faulting-instruction=1 -g %s -o %t && not %run %t 2 >%t.out 2>&1 |
| 22 | +// RUN: FileCheck --check-prefixes VERBOSE-PARAM-CHECK,PARAM-CHECK %s < %t.out |
| 23 | + |
| 24 | +// RUN: %clangxx_msan -fsanitize-memory-param-retval -mllvm -msan-print-faulting-instruction=2 -g %s -o %t && not %run %t 2 >%t.out 2>&1 |
| 25 | +// RUN: FileCheck --check-prefixes VERY-VERBOSE-PARAM-CHECK,PARAM-CHECK %s < %t.out |
| 26 | + |
| 27 | +// Try parameter '2', with -fno-sanitize-memory-param-retval |
| 28 | +// ------------------------------------------------------- |
| 29 | +// RUN: %clangxx_msan -fno-sanitize-memory-param-retval -g %s -o %t && not %run %t 2 >%t.out 2>&1 |
| 30 | +// RUN: FileCheck --check-prefix NO-PARAM-CHECK %s < %t.out |
| 31 | + |
| 32 | +// RUN: %clangxx_msan -fno-sanitize-memory-param-retval -mllvm -msan-print-faulting-instruction=1 -g %s -o %t && not %run %t 2 >%t.out 2>&1 |
| 33 | +// RUN: FileCheck --check-prefixes VERBOSE-NO-PARAM-CHECK,NO-PARAM-CHECK %s < %t.out |
| 34 | + |
| 35 | +// RUN: %clangxx_msan -fno-sanitize-memory-param-retval -mllvm -msan-print-faulting-instruction=2 -g %s -o %t && not %run %t 2 >%t.out 2>&1 |
| 36 | +// RUN: FileCheck --check-prefixes VERY-VERBOSE-NO-PARAM-CHECK,NO-PARAM-CHECK %s < %t.out |
| 37 | + |
| 38 | +#include <stdio.h> |
| 39 | +#include <stdlib.h> |
| 40 | + |
| 41 | +#define THRICE(o,t) twice(o,t) |
| 42 | + |
| 43 | +__attribute__((noinline)) extern "C" int twice(int o, int t) { |
| 44 | + return o + t < 3; |
| 45 | +} |
| 46 | + |
| 47 | +int main(int argc, char *argv[]) { |
| 48 | + int buf[100]; |
| 49 | + buf[0] = 42; |
| 50 | + buf[1] = 43; |
| 51 | + |
| 52 | + if (argc != 2) { |
| 53 | + printf("Usage: %s index\n", argv[0]); |
| 54 | + return 1; |
| 55 | + } |
| 56 | + |
| 57 | + int index = atoi(argv[1]); |
| 58 | + int val = buf[index]; |
| 59 | + |
| 60 | + printf("index %d, abs(val) %d, THRICE(val,5) %d\n", index, abs(val), THRICE(val,5)); |
| 61 | + // VERY-VERBOSE-PARAM-CHECK: Instruction that failed the shadow check: %{{.*}} = call noundef i32 @twice(i32 noundef %{{.*}}, i32 noundef 5) |
| 62 | + // VERBOSE-PARAM-CHECK: Instruction that failed the shadow check: call twice |
| 63 | + // PARAM-CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value |
| 64 | + // PARAM-CHECK: {{#0 0x.* in main .*print_faulting_inst.cpp:}}[[@LINE-4]] |
| 65 | + |
| 66 | + if (val) |
| 67 | + // VERY-VERBOSE-NO-PARAM-CHECK: Instruction that failed the shadow check: br i1 %{{.*}}, label %{{.*}}, label %{{.*}} |
| 68 | + // VERBOSE-NO-PARAM-CHECK: Instruction that failed the shadow check: br |
| 69 | + // NO-PARAM-CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value |
| 70 | + // NO-PARAM-CHECK: {{#0 0x.* in main .*print_faulting_inst.cpp:}}[[@LINE-4]] |
| 71 | + printf("Variable is non-zero\n"); |
| 72 | + else |
| 73 | + printf("Variable is zero\n"); |
| 74 | + |
| 75 | + int nextval = buf[index + 1]; |
| 76 | + buf[nextval + abs(index)] = twice(index,6); |
| 77 | + // VERY-VERBOSE-STORE-CHECK: Instruction that failed the shadow check: store i32 %{{.*}}, ptr %{{.*}} |
| 78 | + // VERBOSE-STORE-CHECK: Instruction that failed the shadow check: store |
| 79 | + // STORE-CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value |
| 80 | + // STORE-CHECK: {{#0 0x.* in main .*print_faulting_inst.cpp:}}[[@LINE-4]] |
| 81 | + |
| 82 | + return 0; |
| 83 | +} |
0 commit comments