1// RUN: %clangxx -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s 2 3// REQUIRES: stable-runtime 4 5#include <sanitizer/common_interface_defs.h> 6#include <stdio.h> 7 8volatile char *zero = 0; 9 10void Death() { 11 fprintf(stderr, "DEATH CALLBACK EXECUTED\n"); 12} 13// CHECK: DEATH CALLBACK EXECUTED 14 15char global; 16volatile char *sink; 17 18__attribute__((noinline)) 19void MaybeInit(int *uninitialized) { 20 if (zero) 21 *uninitialized = 1; 22} 23 24__attribute__((noinline)) 25void Leak() { 26 sink = new char[100]; // trigger lsan report. 27} 28 29int main(int argc, char **argv) { 30 int uninitialized; 31 __sanitizer_set_death_callback(Death); 32 MaybeInit(&uninitialized); 33 if (uninitialized) // trigger msan report. 34 global = 77; 35 sink = new char[100]; 36 delete[] sink; 37 global = sink[0]; // use-after-free: trigger asan/tsan report. 38 Leak(); 39 sink = 0; 40} 41