[clang] [compiler-rt] [compiler-rt] Add print_coverage_summary to silence SanitizerCoverage dump logs (PR #228039)
Manuel Carrasco via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 04:10:24 PDT 2026
https://github.com/mgcarrasco created https://github.com/llvm/llvm-project/pull/228039
When running a test suite of SanitizerCoverage-instrumented binaries, the `SanitizerCoverage: … PCs written` summary on stderr can poison FileCheck and cause unexpected failures.
There is no way to turn that print off today. At most you can use `log_path`, but that still creates a text file per process. We could have guard it on the verbosity option, but that would change the default and may regress consumers that rely on this output.
This PR adds `print_coverage_summary` (default true). Set `print_coverage_summary=0` to keep the dump log disable; .sancov files are still written. The same guard is used on the Fuchsia path.
The new lit test is a copy of sanitizer_coverage_trace_pc_guard.cpp, adapted to check the default print and print_coverage_summary=0.
>From ff7aed5385f1b3bb1b9a86ee0958f6fc13e2d2bb Mon Sep 17 00:00:00 2001
From: Manuel Carrasco <Manuel.Carrasco at amd.com>
Date: Thu, 1 Oct 2026 06:06:01 -0500
Subject: [PATCH] [compiler-rt] Add print_coverage_summary to silence
SanitizerCoverage dump logs
Coverage dumps still write .sancov files; only the "PCs written" summary is
optional.
---
clang/docs/SanitizerCoverage.md | 4 +++
.../sanitizer_coverage_fuchsia.cpp | 5 +--
.../sanitizer_coverage_libcdep_new.cpp | 3 +-
.../lib/sanitizer_common/sanitizer_flags.inc | 2 ++
.../TestCases/sanitizer_coverage_summary.cpp | 33 +++++++++++++++++++
5 files changed, 44 insertions(+), 3 deletions(-)
create mode 100644 compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_summary.cpp
diff --git a/clang/docs/SanitizerCoverage.md b/clang/docs/SanitizerCoverage.md
index 5630d46900f17..ae074d13f5322 100644
--- a/clang/docs/SanitizerCoverage.md
+++ b/clang/docs/SanitizerCoverage.md
@@ -530,6 +530,10 @@ SanitizerCoverage: ./a.out.7316.sancov 3 PCs written
32 a.out.7316.sancov
```
+Set `print_coverage_summary=0` (for example,
+`ASAN_OPTIONS=coverage=1:print_coverage_summary=0`) to suppress the
+`SanitizerCoverage:` summary line. Coverage files are still written.
+
Every time you run an executable instrumented with SanitizerCoverage
one `*.sancov` file is created during the process shutdown.
If the executable is dynamically linked against instrumented DSOs,
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_fuchsia.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_fuchsia.cpp
index 73668a56218cf..284784aa924b6 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_fuchsia.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_fuchsia.cpp
@@ -105,8 +105,9 @@ class TracePcGuardController final {
// uses the `dumpfile` symbolizer markup element to highlight the
// dump. See the explanation for this in:
// https://fuchsia.googlesource.com/zircon/+/master/docs/symbolizer_markup.md
- Printf("SanitizerCoverage: " FORMAT_DUMPFILE " with up to %u PCs\n",
- kSancovSinkName, vmo_name_, next_index_ - 1);
+ if (common_flags()->print_coverage_summary)
+ Printf("SanitizerCoverage: " FORMAT_DUMPFILE " with up to %u PCs\n",
+ kSancovSinkName, vmo_name_, next_index_ - 1);
}
}
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp
index 506659a58c45e..2f5b6f68afa41 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp
@@ -53,7 +53,8 @@ static void WriteModuleCoverage(char* file_path, const char* module_name,
WriteToFile(fd, &Magic, sizeof(Magic));
WriteToFile(fd, pcs, len * sizeof(*pcs));
CloseFile(fd);
- Printf("SanitizerCoverage: %s: %zd PCs written\n", file_path, len);
+ if (common_flags()->print_coverage_summary)
+ Printf("SanitizerCoverage: %s: %zd PCs written\n", file_path, len);
}
static void SanitizerDumpCoverage(const uptr* unsorted_pcs, uptr len) {
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc b/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc
index 5f449907f6011..c094ce544eaa7 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc
@@ -170,6 +170,8 @@ COMMON_FLAG(
COMMON_FLAG(const char *, coverage_dir, ".",
"Target directory for coverage dumps. Defaults to the current "
"directory.")
+COMMON_FLAG(bool, print_coverage_summary, true,
+ "Print the SanitizerCoverage dump summary.")
COMMON_FLAG(const char *, cov_8bit_counters_out, "",
"If non-empty, write 8bit counters to this file. ")
COMMON_FLAG(const char *, cov_pcs_out, "",
diff --git a/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_summary.cpp b/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_summary.cpp
new file mode 100644
index 0000000000000..76177d7fad235
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_summary.cpp
@@ -0,0 +1,33 @@
+// Tests print_coverage_summary for SanitizerCoverage dumps.
+
+// REQUIRES: has_sancovcc
+// UNSUPPORTED: ubsan,i386-darwin,target={{(powerpc64|s390x|sparc|thumb).*}}
+// This test is failing for lsan on darwin on x86_64h.
+// UNSUPPORTED: x86_64h-darwin && lsan
+// XFAIL: tsan
+// XFAIL: android && asan
+// XFAIL: darwin-remote
+// UNSUPPORTED: rtsan
+
+// RUN: rm -rf %t_workdir
+// RUN: mkdir -p %t_workdir
+// RUN: cd %t_workdir
+// RUN: %clangxx -O0 -fsanitize-coverage=trace-pc-guard %s -o %t
+// RUN: %env_tool_opts=coverage=1 %t 2>&1 | FileCheck %s --check-prefix=CHECK-DEFAULT
+// RUN: rm -f *.sancov
+// RUN: %env_tool_opts=coverage=1:print_coverage_summary=0 %t 2>&1 | FileCheck %s --check-prefix=CHECK-QUIET
+// RUN: ls *.sancov
+// RUN: rm -rf %t_workdir
+
+#include <stdio.h>
+
+int main() {
+ fprintf(stderr, "main\n");
+ return 0;
+}
+
+// CHECK-DEFAULT: main
+// CHECK-DEFAULT: SanitizerCoverage: {{.*}}.sancov: {{[0-9]+}} PCs written
+
+// CHECK-QUIET: main
+// CHECK-QUIET-NOT: SanitizerCoverage
More information about the llvm-commits
mailing list