diff --git a/compiler-rt/lib/asan/asan_internal.h b/compiler-rt/lib/asan/asan_internal.h --- a/compiler-rt/lib/asan/asan_internal.h +++ b/compiler-rt/lib/asan/asan_internal.h @@ -134,6 +134,7 @@ // Used to avoid infinite recursion in __asan_init(). extern bool asan_init_is_running; extern bool replace_intrin_cached; +extern int asan_report_count; extern void (*death_callback)(void); // These magic values are written to shadow for better error // reporting. diff --git a/compiler-rt/lib/asan/asan_report.cpp b/compiler-rt/lib/asan/asan_report.cpp --- a/compiler-rt/lib/asan/asan_report.cpp +++ b/compiler-rt/lib/asan/asan_report.cpp @@ -132,6 +132,7 @@ asanThreadRegistry().Lock(); Printf( "=================================================================\n"); + ++asan_report_count; } ~ScopedInErrorReport() { diff --git a/compiler-rt/lib/asan/asan_rtl.cpp b/compiler-rt/lib/asan/asan_rtl.cpp --- a/compiler-rt/lib/asan/asan_rtl.cpp +++ b/compiler-rt/lib/asan/asan_rtl.cpp @@ -74,6 +74,7 @@ int asan_inited; bool asan_init_is_running; bool replace_intrin_cached; +int asan_report_count = 0; #if !ASAN_FIXED_MAPPING uptr kHighMemEnd, kMidMemBeg, kMidMemEnd; @@ -305,15 +306,24 @@ } static void asan_atexit() { - Printf("AddressSanitizer exit stats:\n"); - __asan_print_accumulated_stats(); - // Print AsanMappingProfile. - for (uptr i = 0; i < kAsanMappingProfileSize; i++) { - if (AsanMappingProfile[i] == 0) continue; - Printf("asan_mapping.h:%zd -- %zd\n", i, AsanMappingProfile[i]); + if (flags()->print_stats && (flags()->atexit || asan_report_count > 0)) { + Printf("AddressSanitizer exit stats:\n"); + __asan_print_accumulated_stats(); + // Print AsanMappingProfile. + for (uptr i = 0; i < kAsanMappingProfileSize; i++) { + if (AsanMappingProfile[i] == 0) + continue; + Printf("asan_mapping.h:%zd -- %zd\n", i, AsanMappingProfile[i]); + } + } + if (asan_report_count > 0) { + if (common_flags()->exitcode) + internal__exit(common_flags()->exitcode); } } +static void InstallAtExitHandler() { Atexit(asan_atexit); } + static void InitializeHighMemEnd() { #if !ASAN_FIXED_MAPPING kHighMemEnd = GetMaxUserVirtualAddress(); @@ -463,8 +473,7 @@ asan_inited = 1; asan_init_is_running = false; - if (flags()->atexit) - Atexit(asan_atexit); + InstallAtExitHandler(); InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir); diff --git a/compiler-rt/test/asan/TestCases/Linux/aligned_delete_test.cpp b/compiler-rt/test/asan/TestCases/Linux/aligned_delete_test.cpp --- a/compiler-rt/test/asan/TestCases/Linux/aligned_delete_test.cpp +++ b/compiler-rt/test/asan/TestCases/Linux/aligned_delete_test.cpp @@ -1,10 +1,10 @@ // RUN: %clangxx_asan -std=c++1z -faligned-allocation -fsanitize-recover=address -O0 %s -o %t -// RUN: %env_asan_opts=new_delete_type_mismatch=1:halt_on_error=false:detect_leaks=false %run %t 2>&1 | FileCheck %s -// RUN: %env_asan_opts=new_delete_type_mismatch=0 %run %t +// RUN: %env_asan_opts=new_delete_type_mismatch=1:halt_on_error=false:detect_leaks=false not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=new_delete_type_mismatch=0 %run %t // RUN: %clangxx_asan -std=c++1z -faligned-allocation -fsized-deallocation -fsanitize-recover=address -O0 %s -o %t -// RUN: %env_asan_opts=new_delete_type_mismatch=1:halt_on_error=false:detect_leaks=false %run %t 2>&1 | FileCheck %s -// RUN: %env_asan_opts=new_delete_type_mismatch=0 %run %t +// RUN: %env_asan_opts=new_delete_type_mismatch=1:halt_on_error=false:detect_leaks=false not %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=new_delete_type_mismatch=0 %run %t #include diff --git a/compiler-rt/test/asan/TestCases/Posix/halt_on_error-torture.cpp b/compiler-rt/test/asan/TestCases/Posix/halt_on_error-torture.cpp --- a/compiler-rt/test/asan/TestCases/Posix/halt_on_error-torture.cpp +++ b/compiler-rt/test/asan/TestCases/Posix/halt_on_error-torture.cpp @@ -2,7 +2,7 @@ // // RUN: %clangxx_asan -fsanitize-recover=address -pthread %s -o %t // -// RUN: %env_asan_opts=halt_on_error=false:suppress_equal_pcs=false %run %t 1 10 >%t.log 2>&1 +// RUN: %env_asan_opts=halt_on_error=false:suppress_equal_pcs=false:exitcode=0 %run %t 1 10 >%t.log 2>&1 // RUN: grep 'ERROR: AddressSanitizer: use-after-poison' %t.log | count 10 // RUN: FileCheck %s <%t.log // diff --git a/compiler-rt/test/asan/TestCases/Posix/halt_on_error_suppress_equal_pcs.cpp b/compiler-rt/test/asan/TestCases/Posix/halt_on_error_suppress_equal_pcs.cpp --- a/compiler-rt/test/asan/TestCases/Posix/halt_on_error_suppress_equal_pcs.cpp +++ b/compiler-rt/test/asan/TestCases/Posix/halt_on_error_suppress_equal_pcs.cpp @@ -3,18 +3,18 @@ // RUN: %clang_asan -fsanitize-recover=address %s -o %t // // Check for reports dedupication. -// RUN: %env_asan_opts=halt_on_error=false %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=halt_on_error=false not %run %t 2>&1 | FileCheck %s // // Check that we die after reaching different reports number threshold. // RUN: %env_asan_opts=halt_on_error=false not %run %t 1 >%t1.log 2>&1 // RUN: grep 'ERROR: AddressSanitizer: stack-buffer-overflow' %t1.log | count 25 // // Check suppress_equal_pcs=true behavior is equal to default one. -// RUN: %env_asan_opts=halt_on_error=false:suppress_equal_pcs=true %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=halt_on_error=false:suppress_equal_pcs=true not %run %t 2>&1 | FileCheck %s // // Check suppress_equal_pcs=false behavior isn't equal to default one. // RUN: rm -f %t2.log -// RUN: %env_asan_opts=halt_on_error=false:suppress_equal_pcs=false %run %t >%t2.log 2>&1 +// RUN: %env_asan_opts=halt_on_error=false:suppress_equal_pcs=false not %run %t >%t2.log 2>&1 // RUN: grep 'ERROR: AddressSanitizer: stack-buffer-overflow' %t2.log | count 30 #define ACCESS_ARRAY_FIVE_ELEMENTS(array, i) \ diff --git a/compiler-rt/test/asan/TestCases/double-free.cpp b/compiler-rt/test/asan/TestCases/double-free.cpp --- a/compiler-rt/test/asan/TestCases/double-free.cpp +++ b/compiler-rt/test/asan/TestCases/double-free.cpp @@ -6,7 +6,7 @@ // RUN: %env_asan_opts=malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s // RUN: %clangxx_asan -O0 -fsanitize-recover=address %s -o %t 2>&1 -// RUN: %env_asan_opts=halt_on_error=false %run %t 2>&1 | FileCheck %s --check-prefix CHECK-RECOVER +// RUN: %env_asan_opts=halt_on_error=false not %run %t 2>&1 | FileCheck %s --check-prefix CHECK-RECOVER // REQUIRES: stable-runtime #include diff --git a/compiler-rt/test/asan/TestCases/halt_on_error-1.c b/compiler-rt/test/asan/TestCases/halt_on_error-1.c --- a/compiler-rt/test/asan/TestCases/halt_on_error-1.c +++ b/compiler-rt/test/asan/TestCases/halt_on_error-1.c @@ -4,7 +4,7 @@ // // RUN: env not %run %t 2>&1 | FileCheck %s // RUN: %env_asan_opts=halt_on_error=true not %run %t 2>&1 | FileCheck %s -// RUN: %env_asan_opts=halt_on_error=false %run %t 2>&1 | FileCheck %s --check-prefix CHECK-RECOVER +// RUN: %env_asan_opts=halt_on_error=false not %run %t 2>&1 | FileCheck %s --check-prefix CHECK-RECOVER #include diff --git a/compiler-rt/test/asan/TestCases/invalid-pointer-pairs-compare-errors.cpp b/compiler-rt/test/asan/TestCases/invalid-pointer-pairs-compare-errors.cpp --- a/compiler-rt/test/asan/TestCases/invalid-pointer-pairs-compare-errors.cpp +++ b/compiler-rt/test/asan/TestCases/invalid-pointer-pairs-compare-errors.cpp @@ -1,6 +1,6 @@ // RUN: %clangxx_asan -O0 %s -o %t -mllvm -asan-detect-invalid-pointer-pair -// RUN: %env_asan_opts=detect_invalid_pointer_pairs=2:halt_on_error=0 %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=detect_invalid_pointer_pairs=2:halt_on_error=0 not %run %t 2>&1 | FileCheck %s #include #include diff --git a/compiler-rt/test/asan/TestCases/invalid-pointer-pairs-subtract-errors.cpp b/compiler-rt/test/asan/TestCases/invalid-pointer-pairs-subtract-errors.cpp --- a/compiler-rt/test/asan/TestCases/invalid-pointer-pairs-subtract-errors.cpp +++ b/compiler-rt/test/asan/TestCases/invalid-pointer-pairs-subtract-errors.cpp @@ -1,6 +1,6 @@ // RUN: %clangxx_asan -O0 %s -o %t -mllvm -asan-detect-invalid-pointer-pair -// RUN: %env_asan_opts=detect_invalid_pointer_pairs=2:halt_on_error=0 %run %t 2>&1 | FileCheck %s +// RUN: %env_asan_opts=detect_invalid_pointer_pairs=2:halt_on_error=0 not %run %t 2>&1 | FileCheck %s #include #include