From dc5809021372a8cba1e085b80d263bc101b49a70 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Fri, 29 Nov 2013 14:49:32 +0000 Subject: [PATCH] [asan] dump coverage even if asan has reported an error llvm-svn: 195959 --- compiler-rt/lib/asan/asan_rtl.cc | 2 ++ compiler-rt/lib/asan/lit_tests/TestCases/Linux/coverage.cc | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/compiler-rt/lib/asan/asan_rtl.cc b/compiler-rt/lib/asan/asan_rtl.cc index a1b9fd542acb..25cafc8dcab7 100644 --- a/compiler-rt/lib/asan/asan_rtl.cc +++ b/compiler-rt/lib/asan/asan_rtl.cc @@ -51,6 +51,8 @@ static void AsanDie() { UnmapOrDie((void*)kLowShadowBeg, kHighShadowEnd - kLowShadowBeg); } } + if (flags()->coverage) + __sanitizer_cov_dump(); if (death_callback) death_callback(); if (flags()->abort_on_error) diff --git a/compiler-rt/lib/asan/lit_tests/TestCases/Linux/coverage.cc b/compiler-rt/lib/asan/lit_tests/TestCases/Linux/coverage.cc index 4373e9b13c68..f8a1234751bb 100644 --- a/compiler-rt/lib/asan/lit_tests/TestCases/Linux/coverage.cc +++ b/compiler-rt/lib/asan/lit_tests/TestCases/Linux/coverage.cc @@ -5,6 +5,7 @@ // RUN: %t foo 2>&1 | FileCheck %s --check-prefix=CHECK-foo // RUN: %t bar 2>&1 | FileCheck %s --check-prefix=CHECK-bar // RUN: %t foo bar 2>&1 | FileCheck %s --check-prefix=CHECK-foo-bar +// RUN: not %t foo bar 1 2 2>&1 | FileCheck %s --check-prefix=CHECK-report #include #include @@ -17,6 +18,8 @@ __attribute__((noinline)) void foo() { printf("foo\n"); } extern void bar(); +int G[4]; + int main(int argc, char **argv) { fprintf(stderr, "PID: %d\n", getpid()); for (int i = 1; i < argc; i++) { @@ -25,6 +28,7 @@ int main(int argc, char **argv) { if (!strcmp(argv[i], "bar")) bar(); } + return G[argc]; // Buffer overflow if argc >= 4. } #endif @@ -43,3 +47,6 @@ int main(int argc, char **argv) { // CHECK-foo-bar: PID: [[PID:[0-9]+]] // CHECK-foo-bar: [[PID]].sancov: 2 PCs written // CHECK-foo-bar: so.[[PID]].sancov: 1 PCs written +// +// CHECK-report: AddressSanitizer: global-buffer-overflow +// CHECK-report: PCs written