[compiler-rt] r194685 - [Sanitizer] Add print_summary runtime flag to disable error summaries (UBSan doesn't need them)

Alexey Samsonov samsonov at google.com
Thu Nov 14 00:56:59 PST 2013


Author: samsonov
Date: Thu Nov 14 02:56:59 2013
New Revision: 194685

URL: http://llvm.org/viewvc/llvm-project?rev=194685&view=rev
Log:
[Sanitizer] Add print_summary runtime flag to disable error summaries (UBSan doesn't need them)

Added:
    compiler-rt/trunk/lib/asan/lit_tests/TestCases/print_summary.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h

Added: compiler-rt/trunk/lib/asan/lit_tests/TestCases/print_summary.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/TestCases/print_summary.cc?rev=194685&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/TestCases/print_summary.cc (added)
+++ compiler-rt/trunk/lib/asan/lit_tests/TestCases/print_summary.cc Thu Nov 14 02:56:59 2013
@@ -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
+}
+

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc?rev=194685&r1=194684&r2=194685&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc Thu Nov 14 02:56:59 2013
@@ -166,6 +166,8 @@ void PrintModuleAndOffset(const char *mo
 }
 
 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 *erro
 
 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 *erro
 }
 
 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()) {

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc?rev=194685&r1=194684&r2=194685&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc Thu Nov 14 02:56:59 2013
@@ -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 ch
   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)

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h?rev=194685&r1=194684&r2=194685&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h Thu Nov 14 02:56:59 2013
@@ -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() {





More information about the llvm-commits mailing list