[llvm] [llvm-cov] let text mode divider honor `--show-branch-summary` `--show-region-summary` etc (PR #96016)
Wentao Zhang via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 19 00:21:53 PDT 2024
https://github.com/whentojump updated https://github.com/llvm/llvm-project/pull/96016
>From 0c3f5255c95dc4bf1f5e43aeedd91a08cd9db693 Mon Sep 17 00:00:00 2001
From: Wentao Zhang <zhangwt1997 at gmail.com>
Date: Tue, 18 Jun 2024 21:32:13 -0500
Subject: [PATCH 1/2] [llvm-cov] let text mode divider honor
--show-branch-summary --show-region-summary etc
---
llvm/tools/llvm-cov/CoverageReport.cpp | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/llvm/tools/llvm-cov/CoverageReport.cpp b/llvm/tools/llvm-cov/CoverageReport.cpp
index 49a35f2a943e6..463460b0553f8 100644
--- a/llvm/tools/llvm-cov/CoverageReport.cpp
+++ b/llvm/tools/llvm-cov/CoverageReport.cpp
@@ -102,8 +102,16 @@ void adjustColumnWidths(ArrayRef<StringRef> Files,
/// Prints a horizontal divider long enough to cover the given column
/// widths.
-void renderDivider(ArrayRef<size_t> ColumnWidths, raw_ostream &OS) {
+void renderDivider(ArrayRef<size_t> ColumnWidths, raw_ostream &OS, const CoverageViewOptions &Options) {
size_t Length = std::accumulate(ColumnWidths.begin(), ColumnWidths.end(), 0);
+ if (!Options.ShowRegionSummary)
+ Length -= (FileReportColumns[1] + FileReportColumns[2] + FileReportColumns[3]);
+ if (!Options.ShowInstantiationSummary)
+ Length -= (FileReportColumns[7] + FileReportColumns[8] + FileReportColumns[9]);
+ if (!Options.ShowBranchSummary)
+ Length -= (FileReportColumns[13] + FileReportColumns[14] + FileReportColumns[15]);
+ if (!Options.ShowMCDCSummary)
+ Length -= (FileReportColumns[16] + FileReportColumns[17] + FileReportColumns[18]);
for (size_t I = 0; I < Length; ++I)
OS << '-';
}
@@ -405,7 +413,7 @@ void CoverageReport::renderFunctionReports(ArrayRef<std::string> Files,
<< column("Miss", FunctionReportColumns[11], Column::RightAlignment)
<< column("Cover", FunctionReportColumns[12], Column::RightAlignment);
OS << "\n";
- renderDivider(FunctionReportColumns, OS);
+ renderDivider(FunctionReportColumns, OS, Options);
OS << "\n";
FunctionCoverageSummary Totals("TOTAL");
for (const auto &F : Functions) {
@@ -418,7 +426,7 @@ void CoverageReport::renderFunctionReports(ArrayRef<std::string> Files,
render(Function, DC, OS);
}
if (Totals.ExecutionCount) {
- renderDivider(FunctionReportColumns, OS);
+ renderDivider(FunctionReportColumns, OS, Options);
OS << "\n";
render(Totals, DC, OS);
}
@@ -544,7 +552,7 @@ void CoverageReport::renderFileReports(
Column::RightAlignment)
<< column("Cover", FileReportColumns[18], Column::RightAlignment);
OS << "\n";
- renderDivider(FileReportColumns, OS);
+ renderDivider(FileReportColumns, OS, Options);
OS << "\n";
std::vector<const FileCoverageSummary *> EmptyFiles;
@@ -563,7 +571,7 @@ void CoverageReport::renderFileReports(
render(*FCS, OS);
}
- renderDivider(FileReportColumns, OS);
+ renderDivider(FileReportColumns, OS, Options);
OS << "\n";
render(Totals, OS);
}
>From 8c8bef4b4dfc904bd94ffec49452e9c932da4683 Mon Sep 17 00:00:00 2001
From: Wentao Zhang <zhangwt1997 at gmail.com>
Date: Wed, 19 Jun 2024 02:21:28 -0500
Subject: [PATCH 2/2] fix
---
llvm/tools/llvm-cov/CoverageReport.cpp | 37 ++++++++++++++++----------
1 file changed, 23 insertions(+), 14 deletions(-)
diff --git a/llvm/tools/llvm-cov/CoverageReport.cpp b/llvm/tools/llvm-cov/CoverageReport.cpp
index 463460b0553f8..00aea4039bfde 100644
--- a/llvm/tools/llvm-cov/CoverageReport.cpp
+++ b/llvm/tools/llvm-cov/CoverageReport.cpp
@@ -102,16 +102,25 @@ void adjustColumnWidths(ArrayRef<StringRef> Files,
/// Prints a horizontal divider long enough to cover the given column
/// widths.
-void renderDivider(ArrayRef<size_t> ColumnWidths, raw_ostream &OS, const CoverageViewOptions &Options) {
- size_t Length = std::accumulate(ColumnWidths.begin(), ColumnWidths.end(), 0);
- if (!Options.ShowRegionSummary)
- Length -= (FileReportColumns[1] + FileReportColumns[2] + FileReportColumns[3]);
- if (!Options.ShowInstantiationSummary)
- Length -= (FileReportColumns[7] + FileReportColumns[8] + FileReportColumns[9]);
- if (!Options.ShowBranchSummary)
- Length -= (FileReportColumns[13] + FileReportColumns[14] + FileReportColumns[15]);
- if (!Options.ShowMCDCSummary)
- Length -= (FileReportColumns[16] + FileReportColumns[17] + FileReportColumns[18]);
+void renderDivider(raw_ostream &OS, const CoverageViewOptions &Options, bool isFileReport) {
+ size_t Length;
+ if (isFileReport) {
+ Length = std::accumulate(std::begin(FileReportColumns), std::end(FileReportColumns), 0);
+ if (!Options.ShowRegionSummary)
+ Length -= (FileReportColumns[1] + FileReportColumns[2] + FileReportColumns[3]);
+ if (!Options.ShowInstantiationSummary)
+ Length -= (FileReportColumns[7] + FileReportColumns[8] + FileReportColumns[9]);
+ if (!Options.ShowBranchSummary)
+ Length -= (FileReportColumns[13] + FileReportColumns[14] + FileReportColumns[15]);
+ if (!Options.ShowMCDCSummary)
+ Length -= (FileReportColumns[16] + FileReportColumns[17] + FileReportColumns[18]);
+ } else {
+ Length = std::accumulate(std::begin(FunctionReportColumns), std::end(FunctionReportColumns), 0);
+ if (!Options.ShowBranchSummary)
+ Length -= (FunctionReportColumns[7] + FunctionReportColumns[8] + FunctionReportColumns[9]);
+ if (!Options.ShowMCDCSummary)
+ Length -= (FunctionReportColumns[10] + FunctionReportColumns[11] + FunctionReportColumns[12]);
+ }
for (size_t I = 0; I < Length; ++I)
OS << '-';
}
@@ -413,7 +422,7 @@ void CoverageReport::renderFunctionReports(ArrayRef<std::string> Files,
<< column("Miss", FunctionReportColumns[11], Column::RightAlignment)
<< column("Cover", FunctionReportColumns[12], Column::RightAlignment);
OS << "\n";
- renderDivider(FunctionReportColumns, OS, Options);
+ renderDivider(OS, Options, false);
OS << "\n";
FunctionCoverageSummary Totals("TOTAL");
for (const auto &F : Functions) {
@@ -426,7 +435,7 @@ void CoverageReport::renderFunctionReports(ArrayRef<std::string> Files,
render(Function, DC, OS);
}
if (Totals.ExecutionCount) {
- renderDivider(FunctionReportColumns, OS, Options);
+ renderDivider(OS, Options, false);
OS << "\n";
render(Totals, DC, OS);
}
@@ -552,7 +561,7 @@ void CoverageReport::renderFileReports(
Column::RightAlignment)
<< column("Cover", FileReportColumns[18], Column::RightAlignment);
OS << "\n";
- renderDivider(FileReportColumns, OS, Options);
+ renderDivider(OS, Options, true);
OS << "\n";
std::vector<const FileCoverageSummary *> EmptyFiles;
@@ -571,7 +580,7 @@ void CoverageReport::renderFileReports(
render(*FCS, OS);
}
- renderDivider(FileReportColumns, OS, Options);
+ renderDivider(OS, Options, true);
OS << "\n";
render(Totals, OS);
}
More information about the llvm-commits
mailing list