From bb0ade6daa621b300ba68e736dcd19cd3c3bcc71 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Wed, 25 Jul 2012 10:56:09 +0000 Subject: [PATCH] [asan] don't return from a never-return function. fix a test that had a chain of bugs instead of just one llvm-svn: 160719 --- compiler-rt/lib/asan/asan_rtl.cc | 10 ++++++++-- compiler-rt/lib/asan/tests/asan_noinst_test.cc | 12 ++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/compiler-rt/lib/asan/asan_rtl.cc b/compiler-rt/lib/asan/asan_rtl.cc index 5e6e8154718d..34324fa16d08 100644 --- a/compiler-rt/lib/asan/asan_rtl.cc +++ b/compiler-rt/lib/asan/asan_rtl.cc @@ -387,9 +387,15 @@ void NOINLINE __asan_set_error_report_callback(void (*callback)(const char*)) { void __asan_report_error(uptr pc, uptr bp, uptr sp, uptr addr, bool is_write, uptr access_size) { - // Do not print more than one report, otherwise they will mix up. static atomic_uint32_t num_calls; - if (atomic_fetch_add(&num_calls, 1, memory_order_relaxed) != 0) return; + if (atomic_fetch_add(&num_calls, 1, memory_order_relaxed) != 0) { + // Do not print more than one report, otherwise they will mix up. + // We can not return here because the function is marked as never-return. + AsanPrintf("AddressSanitizer: while reporting a bug found another one." + "Ignoring.\n"); + SleepForSeconds(5); + Die(); + } AsanPrintf("====================================================" "=============\n"); diff --git a/compiler-rt/lib/asan/tests/asan_noinst_test.cc b/compiler-rt/lib/asan/tests/asan_noinst_test.cc index 8c3d126090a3..44d4c3c845b2 100644 --- a/compiler-rt/lib/asan/tests/asan_noinst_test.cc +++ b/compiler-rt/lib/asan/tests/asan_noinst_test.cc @@ -670,20 +670,12 @@ TEST(AddressSanitizerInterface, DISABLED_InvalidPoisonAndUnpoisonCallsTest) { } static void ErrorReportCallbackOneToZ(const char *report) { - int len = strlen(report); - char *dup = (char*)malloc(len); - strcpy(dup, report); - for (int i = 0; i < len; i++) { - if (dup[i] == '1') dup[i] = 'Z'; - } - int written = write(2, dup, len); - ASSERT_EQ(len, written); - free(dup); + write(2, "ABCDEF", 6); } TEST(AddressSanitizerInterface, SetErrorReportCallbackTest) { __asan_set_error_report_callback(ErrorReportCallbackOneToZ); - EXPECT_DEATH(__asan_report_error(0, 0, 0, 0, true, 1), "size Z"); + EXPECT_DEATH(__asan_report_error(0, 0, 0, 0, true, 1), "ABCDEF"); __asan_set_error_report_callback(NULL); }