Index: lib/asan/asan_flags.inc =================================================================== --- lib/asan/asan_flags.inc +++ lib/asan/asan_flags.inc @@ -78,7 +78,7 @@ ASAN_FLAG(bool, unmap_shadow_on_exit, false, "If set, explicitly unmaps the (huge) shadow at exit.") ASAN_FLAG( - bool, abort_on_error, false, + bool, abort_on_error, (SANITIZER_MAC == 1), "If set, the tool calls abort() instead of _exit() after printing the " "error report.") ASAN_FLAG(bool, print_stats, false, Index: lib/asan/tests/asan_test_main.cc =================================================================== --- lib/asan/tests/asan_test_main.cc +++ lib/asan/tests/asan_test_main.cc @@ -12,6 +12,15 @@ //===----------------------------------------------------------------------===// #include "asan_test_utils.h" +#if defined(__APPLE__) +extern "C" { +// On OS X, let's override abort_on_error=0 to make unit tests not abort(). +const char* __asan_default_options() { + return "abort_on_error=0"; +} +} // extern "C" +#endif + int main(int argc, char **argv) { testing::GTEST_FLAG(death_test_style) = "threadsafe"; testing::InitGoogleTest(&argc, argv); Index: test/asan/TestCases/Darwin/abort_on_error-darwin.cc =================================================================== --- test/asan/TestCases/Darwin/abort_on_error-darwin.cc +++ test/asan/TestCases/Darwin/abort_on_error-darwin.cc @@ -0,0 +1,16 @@ +// Check that with empty ASAN_OPTIONS, ASan reports on OS X actually crash +// the process (abort_on_error=1). See also Linux/abort_on_error-linux.cc. + +// RUN: %clangxx_asan %s -o %t + +// Intentionally don't inherit the default ASAN_OPTIONS. +// RUN: ASAN_OPTIONS="" not --crash %run %t 2>&1 | FileCheck %s + +#include +int main() { + char *x = (char*)malloc(10 * sizeof(char)); + free(x); + return x[5]; + // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}} + // CHECK: {{0x.* at pc 0x.* bp 0x.* sp 0x.*}} +} Index: test/asan/TestCases/Linux/abort_on_error-linux.cc =================================================================== --- test/asan/TestCases/Linux/abort_on_error-linux.cc +++ test/asan/TestCases/Linux/abort_on_error-linux.cc @@ -0,0 +1,16 @@ +// Check that with empty ASAN_OPTIONS, ASan reports on Linux don't crash +// the process (abort_on_error=0). See also Darwin/abort_on_error-darwin.cc. + +// RUN: %clangxx_asan %s -o %t + +// Intentionally don't inherit the default ASAN_OPTIONS. +// RUN: ASAN_OPTIONS="" not run %t 2>&1 | FileCheck %s + +#include +int main() { + char *x = (char*)malloc(10 * sizeof(char)); + free(x); + return x[5]; + // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}} + // CHECK: {{0x.* at pc 0x.* bp 0x.* sp 0x.*}} +} Index: test/asan/lit.cfg =================================================================== --- test/asan/lit.cfg +++ test/asan/lit.cfg @@ -148,8 +148,12 @@ # Default test suffixes. config.suffixes = ['.c', '.cc', '.cpp'] +# Tests now inherit ASAN_OPTIONS, let's have it empty by default. +config.environment["ASAN_OPTIONS"] = "" + if config.host_os == 'Darwin': config.suffixes.append('.mm') + config.environment["ASAN_OPTIONS"] = "abort_on_error=0" # AddressSanitizer tests are currently supported on Linux, Darwin and # FreeBSD only.