summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test/sanitizer_common/TestCases/Darwin/abort_on_error.cpp
blob: aa3e1dbd9edd78d27a39110237eb7066578c0aa6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Check that sanitizers on OS X crash the process by default (i.e.
// abort_on_error=1). See also Linux/abort_on_error.cpp.

// RUN: %clangxx -DUSING_%tool_name %s -o %t

// Intentionally don't inherit the default options.
// RUN: env %tool_options='' not --crash %run %t 2>&1

// When we use lit's default options, we shouldn't crash.
// RUN: not %run %t 2>&1

// Leak detection isn't treated as an error so `abort_on_error=1` doesn't work.
// UNSUPPORTED: lsan

int global;

int main() {
#if defined(USING_ubsan)
  int value = 5;
  int computation = value / 0; // Division by zero.
#else
  volatile int *a = new int[100];
  delete[] a;
  global = a[0]; // use-after-free: triggers ASan/TSan report.
#endif
  return 0;
}
OpenPOWER on IntegriCloud