xref: /llvm-project/compiler-rt/test/msan/recover.cpp (revision 643a2080ec028bd7674206e0f97cbc7d0f132f99)
1d21b3d34SFangrui Song // RUN: %clangxx_msan -O0 %s -o %t && not %run %t >%t.out 2>&1
2d21b3d34SFangrui Song // FileCheck %s <%t.out
3*643a2080SHarini0924 // RUN: %clangxx_msan -O0 %s -o %t && env MSAN_OPTIONS=keep_going=0 not %run %t >%t.out 2>&1
4d21b3d34SFangrui Song // FileCheck %s <%t.out
5*643a2080SHarini0924 // RUN: %clangxx_msan -O0 %s -o %t && env MSAN_OPTIONS=keep_going=1 not %run %t >%t.out 2>&1
6d21b3d34SFangrui Song // FileCheck %s <%t.out
7d21b3d34SFangrui Song 
8d21b3d34SFangrui Song // Test behavior of -fsanitize-recover=memory and MSAN_OPTIONS=keep_going.
9d21b3d34SFangrui Song // -fsanitize-recover=memory provides the default value of keep_going flag; value
10d21b3d34SFangrui Song // of 1 can be overwritten by MSAN_OPTIONS, value of 0 can not.
11d21b3d34SFangrui Song 
12d21b3d34SFangrui Song // RUN: %clangxx_msan -fsanitize-recover=memory -O0 %s -o %t && not %run %t >%t.out 2>&1
13d21b3d34SFangrui Song // FileCheck --check-prefix=CHECK-RECOVER %s <%t.out
14*643a2080SHarini0924 // RUN: %clangxx_msan -fsanitize-recover=memory -O0 %s -o %t && env MSAN_OPTIONS=keep_going=0 not %run %t >%t.out 2>&1
15d21b3d34SFangrui Song // FileCheck %s <%t.out
16*643a2080SHarini0924 // RUN: %clangxx_msan -fsanitize-recover=memory -O0 %s -o %t && env MSAN_OPTIONS=keep_going=1 not %run %t >%t.out 2>&1
17d21b3d34SFangrui Song // FileCheck --check-prefix=CHECK-RECOVER %s <%t.out
18*643a2080SHarini0924 // RUN: %clangxx_msan -fsanitize-recover=memory -O0 %s -o %t && env MSAN_OPTIONS=halt_on_error=1 not %run %t >%t.out 2>&1
19d21b3d34SFangrui Song // FileCheck %s <%t.out
20*643a2080SHarini0924 // RUN: %clangxx_msan -fsanitize-recover=memory -O0 %s -o %t && env MSAN_OPTIONS=halt_on_error=0 not %run %t >%t.out 2>&1
21d21b3d34SFangrui Song // FileCheck --check-prefix=CHECK-RECOVER %s <%t.out
22d21b3d34SFangrui Song 
23d21b3d34SFangrui Song // Basic test of legacy -mllvm -msan-keep-going and MSAN_OPTIONS=keep_going.
24d21b3d34SFangrui Song 
25d21b3d34SFangrui Song // RUN: %clangxx_msan -mllvm -msan-keep-going=1 -O0 %s -o %t && not %run %t >%t.out 2>&1
26d21b3d34SFangrui Song // FileCheck --check-prefix=CHECK-RECOVER %s <%t.out
27*643a2080SHarini0924 // RUN: %clangxx_msan -mllvm -msan-keep-going=1 -O0 %s -o %t && env MSAN_OPTIONS=keep_going=0 not %run %t >%t.out 2>&1
28d21b3d34SFangrui Song // FileCheck %s <%t.out
29d21b3d34SFangrui Song 
30d21b3d34SFangrui Song #include <stdio.h>
31d21b3d34SFangrui Song #include <stdlib.h>
32d21b3d34SFangrui Song 
33d21b3d34SFangrui Song int main(int argc, char **argv) {
34d21b3d34SFangrui Song   char *volatile x = (char*)malloc(5 * sizeof(char));
35d21b3d34SFangrui Song   if (x[0])
36d21b3d34SFangrui Song     exit(0);
37d21b3d34SFangrui Song   fprintf(stderr, "Done\n");
38d21b3d34SFangrui Song   // CHECK-NOT: Done
39d21b3d34SFangrui Song   // CHECK-RECOVER: Done
40d21b3d34SFangrui Song   return 0;
41d21b3d34SFangrui Song }
42