Index: test/msan/print_stats.cc =================================================================== --- test/msan/print_stats.cc +++ test/msan/print_stats.cc @@ -1,22 +1,22 @@ // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -g %s -o %t // RUN: %run %t 2>&1 | \ -// RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NOSTATS %s +// RUN: FileCheck --check-prefixes=CHECK,CHECK-NOSTATS %s // RUN: MSAN_OPTIONS=print_stats=1 %run %t 2>&1 | \ -// RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NOSTATS %s +// RUN: FileCheck --check-prefixes=CHECK,CHECK-NOSTATS %s // RUN: MSAN_OPTIONS=print_stats=1,atexit=1 %run %t 2>&1 | \ -// RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-STATS %s +// RUN: FileCheck --check-prefixes=CHECK,CHECK-STATS %s // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -g -DPOSITIVE=1 %s -o %t // RUN: not %run %t 2>&1 | \ -// RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NOSTATS %s +// RUN: FileCheck --check-prefixes=CHECK,CHECK-NOSTATS %s // RUN: MSAN_OPTIONS=print_stats=1 not %run %t 2>&1 | \ -// RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-STATS %s +// RUN: FileCheck --check-prefixes=CHECK,CHECK-STATS %s -// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -g -DPOSITIVE=1 -mllvm -msan-keep-going=1 %s -o %t +// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -fsanitize-recover=memory -g -DPOSITIVE=1 %s -o %t // RUN: not %run %t 2>&1 | \ -// RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NOSTATS --check-prefix=CHECK-KEEPGOING %s +// RUN: FileCheck --check-prefixes=CHECK,CHECK-NOSTATS,CHECK-RECOVER %s // RUN: MSAN_OPTIONS=print_stats=1 not %run %t 2>&1 | \ -// RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-STATS --check-prefix=CHECK-KEEPGOING %s +// RUN: FileCheck --check-prefixes=CHECK,CHECK-STATS,CHECK-RECOVER %s #include int main(int argc, char **argv) { @@ -42,4 +42,4 @@ // CHECK-NOSTATS-NOT: Unique origin histories: // CHECK-NOSTATS-NOT: History depot allocated bytes: -// CHECK-KEEPGOING: MemorySanitizer: 1 warnings reported. +// CHECK-RECOVER: MemorySanitizer: 1 warnings reported. Index: test/msan/recover-dso.cc =================================================================== --- /dev/null +++ test/msan/recover-dso.cc @@ -0,0 +1,33 @@ +// RUN: %clangxx_msan -O0 %s -o %t && not %run %t >%t.out 2>&1 +// FileCheck --check-prefix=CHECK-RECOVER %s <%t.out +// RUN: %clangxx_msan -O0 %s -o %t && MSAN_OPTIONS=keep_going=0 not %run %t >%t.out 2>&1 +// FileCheck %s <%t.out +// RUN: %clangxx_msan -O0 %s -o %t && MSAN_OPTIONS=keep_going=1 not %run %t >%t.out 2>&1 +// FileCheck --check-prefix=CHECK-RECOVER %s <%t.out + +// RUN: %clangxx_msan -fsanitize-recover=memory -O0 %s -o %t && not %run %t >%t.out 2>&1 +// FileCheck --check-prefix=CHECK-RECOVER %s <%t.out +// RUN: %clangxx_msan -fsanitize-recover=memory -O0 %s -o %t && MSAN_OPTIONS=keep_going=0 not %run %t >%t.out 2>&1 +// FileCheck %s <%t.out +// RUN: %clangxx_msan -fsanitize-recover=memory -O0 %s -o %t && MSAN_OPTIONS=keep_going=1 not %run %t >%t.out 2>&1 +// FileCheck --check-prefix=CHECK-RECOVER %s <%t.out + +// Test how -fsanitize-recover=memory and MSAN_OPTIONS=keep_going affect reports +// from interceptors. +// -fsanitize-recover=memory provides the default value of keep_going flag, but is +// always overwritten by MSAN_OPTIONS + +#include +#include +#include + +int main(int argc, char **argv) { + char *volatile x = (char*)malloc(5 * sizeof(char)); + x[4] = 0; + if (strlen(x) < 3) + exit(0); + fprintf(stderr, "Done\n"); + // CHECK-NOT: Done + // CHECK-RECOVER: Done + return 0; +} Index: test/msan/recover.cc =================================================================== --- /dev/null +++ test/msan/recover.cc @@ -0,0 +1,34 @@ +// RUN: %clangxx_msan -O0 %s -o %t && not %run %t >%t.out 2>&1 +// FileCheck %s <%t.out +// RUN: %clangxx_msan -O0 %s -o %t && MSAN_OPTIONS=keep_going=0 not %run %t >%t.out 2>&1 +// FileCheck %s <%t.out +// RUN: %clangxx_msan -O0 %s -o %t && MSAN_OPTIONS=keep_going=1 not %run %t >%t.out 2>&1 +// FileCheck %s <%t.out + +// RUN: %clangxx_msan -fsanitize-recover=memory -O0 %s -o %t && not %run %t >%t.out 2>&1 +// FileCheck --check-prefix=CHECK-RECOVER %s <%t.out +// RUN: %clangxx_msan -fsanitize-recover=memory -O0 %s -o %t && MSAN_OPTIONS=keep_going=0 not %run %t >%t.out 2>&1 +// FileCheck %s <%t.out +// RUN: %clangxx_msan -fsanitize-recover=memory -O0 %s -o %t && MSAN_OPTIONS=keep_going=1 not %run %t >%t.out 2>&1 +// FileCheck --check-prefix=CHECK-RECOVER %s <%t.out +// RUN: %clangxx_msan -fsanitize-recover=memory -O0 %s -o %t && MSAN_OPTIONS=halt_on_error=1 not %run %t >%t.out 2>&1 +// FileCheck %s <%t.out +// RUN: %clangxx_msan -fsanitize-recover=memory -O0 %s -o %t && MSAN_OPTIONS=halt_on_error=0 not %run %t >%t.out 2>&1 +// FileCheck --check-prefix=CHECK-RECOVER %s <%t.out + +// Test behaviour of -fsanitize-recover=memory and MSAN_OPTIONS=keep_going. +// -fsanitize-recover=memory provides the default value of keep_going flag; value +// of 1 can be overwritten by MSAN_OPTIONS, value of 0 can not. + +#include +#include + +int main(int argc, char **argv) { + char *volatile x = (char*)malloc(5 * sizeof(char)); + if (x[0]) + exit(0); + fprintf(stderr, "Done\n"); + // CHECK-NOT: Done + // CHECK-RECOVER: Done + return 0; +}