43 lines · cpp
1// RUN: %clangxx_msan -DERROR %s -o %t && not %run %t 2>&1 | \2// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOCB3// RUN: %clangxx_msan -DERROR -DMSANCB_SET %s -o %t && not %run %t 2>&1 | \4// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CB5// RUN: %clangxx_msan -DERROR -DMSANCB_SET -DMSANCB_CLEAR %s -o %t && not %run %t 2>&1 | \6// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOCB7// RUN: %clangxx_msan -DMSANCB_SET %s -o %t && %run %t 2>&1 | \8// RUN: FileCheck %s --check-prefixes=SUCCEED,CHECK-NOCB9 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_SET24 __msan_set_death_callback(cb);25#endif26 27#ifdef MSANCB_CLEAR28 __msan_set_death_callback(0);29#endif30 31#ifdef ERROR32 if (*p)33 exit(0);34#endif35 // CHECK-CB: msan-death-callback36 // CHECK-NOCB-NOT: msan-death-callback37 38 // CHECK-NOT: done39 // SUCCEED: done40 fprintf(stderr, "done\n");41 return 0;42}43