[clang] [compiler-rt] [compiler-rt] Add print_coverage_summary to silence SanitizerCoverage dump logs (PR #228039)
Manuel Carrasco via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 2 02:18:56 PDT 2026
https://github.com/mgcarrasco updated https://github.com/llvm/llvm-project/pull/228039
>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 1/2] [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 5630d46900f1764..ae074d13f5322aa 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 73668a56218cf0f..284784aa924b6fc 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 506659a58c45ecb..2f5b6f68afa4131 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 5f449907f6011f7..c094ce544eaa7d5 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 000000000000000..76177d7fad2359a
--- /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
>From b5a62d149d74566eb6edb810b4e56d684f96dc47 Mon Sep 17 00:00:00 2001
From: Manuel Carrasco <Manuel.Carrasco at amd.com>
Date: Fri, 2 Oct 2026 04:18:28 -0500
Subject: [PATCH 2/2] [reviews] Update test.
---
.../sanitizer_common/TestCases/sanitizer_coverage_summary.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_summary.cpp b/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_summary.cpp
index 76177d7fad2359a..3657d03ffc478f1 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_summary.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_summary.cpp
@@ -15,7 +15,7 @@
// 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: %env_tool_opts=coverage=1:print_coverage_summary=0 %t 2>&1 | FileCheck %s --check-prefix=CHECK-QUIET --implicit-check-not='SanitizerCoverage'
// RUN: ls *.sancov
// RUN: rm -rf %t_workdir
@@ -30,4 +30,3 @@ int main() {
// CHECK-DEFAULT: SanitizerCoverage: {{.*}}.sancov: {{[0-9]+}} PCs written
// CHECK-QUIET: main
-// CHECK-QUIET-NOT: SanitizerCoverage
More information about the cfe-commits
mailing list