Home | History | Annotate | Download | only in Linux
      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 
      8 volatile char *zero = 0;
      9 
     10 void Death() {
     11   fprintf(stderr, "DEATH CALLBACK EXECUTED\n");
     12 }
     13 // CHECK: DEATH CALLBACK EXECUTED
     14 
     15 char global;
     16 volatile char *sink;
     17 
     18 __attribute__((noinline))
     19 void MaybeInit(int *uninitialized) {
     20   if (zero)
     21     *uninitialized = 1;
     22 }
     23 
     24 __attribute__((noinline))
     25 void Leak() {
     26   sink = new char[100];  // trigger lsan report.
     27 }
     28 
     29 int 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