Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / sanitizer_common / TestCases / Posix / sanitizer_set_death_callback_test.cpp
blob9c5ae13cfd8b71fb8a09ae21954d83e3cac438a0
1 // RUN: %clangxx -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
3 // REQUIRES: stable-runtime
5 // XFAIL: ubsan
6 // FIXME: On Darwin, LSAn detects the leak, but does not invoke the death_callback.
7 // XFAIL: darwin && lsan
9 #include <sanitizer/common_interface_defs.h>
10 #include <stdio.h>
12 volatile char *zero = 0;
14 void Death() {
15 fprintf(stderr, "DEATH CALLBACK EXECUTED\n");
17 // CHECK: DEATH CALLBACK EXECUTED
19 char global;
20 volatile char *sink;
22 __attribute__((noinline))
23 void MaybeInit(int *uninitialized) {
24 if (zero)
25 *uninitialized = 1;
28 __attribute__((noinline))
29 void Leak() {
30 // Trigger lsan report. Two attempts in case the address of the first
31 // allocation remained on the stack.
32 sink = new char[100];
33 sink = new char[100];
36 int main(int argc, char **argv) {
37 int uninitialized;
38 __sanitizer_set_death_callback(Death);
39 MaybeInit(&uninitialized);
40 if (uninitialized) // trigger msan report.
41 global = 77;
42 sink = new char[100];
43 delete[] sink;
44 global = sink[0]; // use-after-free: trigger asan/tsan report.
45 Leak();
46 sink = 0;