diff options
| author | Alexey Samsonov <samsonov@google.com> | 2013-11-14 08:56:59 +0000 |
|---|---|---|
| committer | Alexey Samsonov <samsonov@google.com> | 2013-11-14 08:56:59 +0000 |
| commit | 498e5906ad8e0e9959a1ec146cac01850829690e (patch) | |
| tree | 671f3d38d8a9b60abe7f89547d93059c9f278676 | |
| parent | f4760455e80a7c614edc72bdcbfa58eb10d92d35 (diff) | |
| download | bcm5719-llvm-498e5906ad8e0e9959a1ec146cac01850829690e.tar.gz bcm5719-llvm-498e5906ad8e0e9959a1ec146cac01850829690e.zip | |
[Sanitizer] Add print_summary runtime flag to disable error summaries (UBSan doesn't need them)
llvm-svn: 194685
4 files changed, 24 insertions, 0 deletions
diff --git a/compiler-rt/lib/asan/lit_tests/TestCases/print_summary.cc b/compiler-rt/lib/asan/lit_tests/TestCases/print_summary.cc new file mode 100644 index 00000000000..949c9b54f8a --- /dev/null +++ b/compiler-rt/lib/asan/lit_tests/TestCases/print_summary.cc @@ -0,0 +1,14 @@ +// RUN: %clangxx_asan -O0 %s -o %t +// RUN: not %t 2>&1 | FileCheck %s --check-prefix=YES +// RUN: ASAN_OPTIONS=print_summary=false not %t 2>&1 | FileCheck %s --check-prefix=NO + +int main() { + char *x = new char[20]; + delete[] x; + return x[0]; + // YES: ERROR: AddressSanitizer: heap-use-after-free + // YES: SUMMARY: AddressSanitizer: heap-use-after-free + // NO: ERROR: AddressSanitizer: heap-use-after-free + // NO-NOT: SUMMARY: AddressSanitizer: heap-use-after-free +} + diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc index 7f896f9bd89..9c331a8e426 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc @@ -166,6 +166,8 @@ void PrintModuleAndOffset(const char *module, uptr offset) { } void ReportErrorSummary(const char *error_message) { + if (!common_flags()->print_summary) + return; InternalScopedBuffer<char> buff(kMaxSummaryLength); internal_snprintf(buff.data(), buff.size(), "SUMMARY: %s: %s", SanitizerToolName, error_message); @@ -174,6 +176,8 @@ void ReportErrorSummary(const char *error_message) { void ReportErrorSummary(const char *error_type, const char *file, int line, const char *function) { + if (!common_flags()->print_summary) + return; InternalScopedBuffer<char> buff(kMaxSummaryLength); internal_snprintf( buff.data(), buff.size(), "%s %s:%d %s", error_type, @@ -183,6 +187,8 @@ void ReportErrorSummary(const char *error_type, const char *file, } void ReportErrorSummary(const char *error_type, StackTrace *stack) { + if (!common_flags()->print_summary) + return; AddressInfo ai; #if !SANITIZER_GO if (stack->size > 0 && Symbolizer::Get()->IsAvailable()) { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc b/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc index ba23ea04bc2..924ed4bc014 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc @@ -32,6 +32,7 @@ void SetCommonFlagDefaults() { f->detect_leaks = false; f->leak_check_at_exit = true; f->allocator_may_return_null = false; + f->print_summary = true; } void ParseCommonFlagsFromString(const char *str) { @@ -48,6 +49,7 @@ void ParseCommonFlagsFromString(const char *str) { ParseFlag(str, &f->detect_leaks, "detect_leaks"); ParseFlag(str, &f->leak_check_at_exit, "leak_check_at_exit"); ParseFlag(str, &f->allocator_may_return_null, "allocator_may_return_null"); + ParseFlag(str, &f->print_summary, "print_summary"); // Do a sanity check for certain flags. if (f->malloc_context_size < 1) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flags.h b/compiler-rt/lib/sanitizer_common/sanitizer_flags.h index b8a6b15d8bb..9461dff8033 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_flags.h @@ -51,6 +51,8 @@ struct CommonFlags { bool leak_check_at_exit; // If false, the allocator will crash instead of returning 0 on out-of-memory. bool allocator_may_return_null; + // If false, disable printing error summaries in addition to error reports. + bool print_summary; }; inline CommonFlags *common_flags() { |

