1// RUN: %clangxx_msan -DERROR %s -o %t && not %run %t 2>&1 | \
2// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOCB
3// RUN: %clangxx_msan -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 -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 -DMSANCB_SET %s -o %t && %run %t 2>&1 | \
8// RUN: FileCheck %s --check-prefixes=SUCCEED,CHECK-NOCB
9
10#include <sanitizer/msan_interface.h>
11#include <stdio.h>
12#include <stdlib.h>
13
14void cb(void) {
15 fprintf(stderr, format: "msan-death-callback\n");
16}
17
18int main(int argc, char **argv) {
19 int *volatile p = (int *)malloc(size: sizeof(int));
20 *p = 42;
21 free(ptr: 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
38 // CHECK-NOT: done
39 // SUCCEED: done
40 fprintf(stderr, format: "done\n");
41 return 0;
42}
43

source code of compiler-rt/test/msan/death-callback.cpp