// RUN: %clangxx -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s

// REQUIRES: stable-runtime

// XFAIL: ubsan
// FIXME: On Darwin, LSAn detects the leak, but does not invoke the death_callback.
// XFAIL: darwin && lsan

#include <sanitizer/common_interface_defs.h>
#include <stdio.h>

volatile char *zero = 0;

void Death() {
  fprintf(stderr, "DEATH CALLBACK EXECUTED\n");
}
// CHECK: DEATH CALLBACK EXECUTED

char global;
volatile char *sink;

__attribute__((noinline))
void MaybeInit(int *uninitialized) {
  if (zero)
    *uninitialized = 1;
}

__attribute__((noinline))
void Leak() {
  // Trigger lsan report. Two attempts in case the address of the first
  // allocation remained on the stack.
  sink = new char[100];
  sink = new char[100];
}

int main(int argc, char **argv) {
  int uninitialized;
  __sanitizer_set_death_callback(Death);
  MaybeInit(&uninitialized);
  if (uninitialized)  // trigger msan report.
    global = 77;
  sink = new char[100];
  delete[] sink;
  global = sink[0];  // use-after-free: trigger asan/tsan report.
  Leak();
  sink = 0;
}

// RUN: %clangxx -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s

// REQUIRES: stable-runtime

// XFAIL: ubsan
// FIXME(dliew): Make this test work on Darwin with LSan
// XFAIL: darwin && lsan

#include <sanitizer/common_interface_defs.h>
#include <stdio.h>

volatile char *zero = 0;

void Death() {
  fprintf(stderr, "DEATH CALLBACK EXECUTED\n");
}
// CHECK: DEATH CALLBACK EXECUTED

char global;
volatile char *sink;

__attribute__((noinline))
void MaybeInit(int *uninitialized) {
  if (zero)
    *uninitialized = 1;
}

__attribute__((noinline))
void Leak() {
  // Trigger lsan report. Two attempts in case the address of the first
  // allocation remained on the stack.
  sink = new char[100];
  sink = new char[100];
}

int main(int argc, char **argv) {
  int uninitialized;
  __sanitizer_set_death_callback(Death);
  MaybeInit(&uninitialized);
  if (uninitialized)  // trigger msan report.
    global = 77;
  sink = new char[100];
  delete[] sink;
  global = sink[0];  // use-after-free: trigger asan/tsan report.
  Leak();
  sink = 0;
}

--- 
+++ 
@@ -3,7 +3,7 @@
 // REQUIRES: stable-runtime
 
 // XFAIL: ubsan
-// FIXME(dliew): Make this test work on Darwin with LSan
+// FIXME: On Darwin, LSAn detects the leak, but does not invoke the death_callback.
 // XFAIL: darwin && lsan
 
 #include <sanitizer/common_interface_defs.h>
[LSan][Darwin][NFC] Add comment explaining test failure

git-svn-id: c199f293c43da69278bea8e88f92242bf3aa95f7@354290 91177308-0d34-0410-b5e6-96231b3b80d8
