1// RUN: %clangxx_msan -m64 -DERROR %s -o %t && not %run %t 2>&1 | \ 2// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOCB 3// RUN: %clangxx_msan -m64 -DERROR -DMSANCB_SET %s -o %t && not %run %t 2>&1 | \ 4// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CB 5// RUN: %clangxx_msan -m64 -DERROR -DMSANCB_SET -DMSANCB_CLEAR %s -o %t && not %run %t 2>&1 | \ 6// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOCB 7// RUN: %clangxx_msan -m64 -DMSANCB_SET %s -o %t && %run %t 2>&1 | \ 8// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOCB 9 10#include <sanitizer/msan_interface.h> 11#include <stdio.h> 12#include <stdlib.h> 13 14void cb(void) { 15 fprintf(stderr, "msan-death-callback\n"); 16} 17 18int main(int argc, char **argv) { 19 int *volatile p = (int *)malloc(sizeof(int)); 20 *p = 42; 21 free(p); 22 23#ifdef MSANCB_SET 24 __msan_set_death_callback(cb); 25#endif 26 27#ifdef MSANCB_CLEAR 28 __msan_set_death_callback(0); 29#endif 30 31#ifdef ERROR 32 if (*p) 33 exit(0); 34#endif 35 // CHECK-CB: msan-death-callback 36 // CHECK-NOCB-NOT: msan-death-callback 37 fprintf(stderr, "done\n"); 38 return 0; 39} 40