[llvm] 61e62ce - [llvm-cov] let text mode divider honor --show-branch-summary, --show-region-summary etc (#96016)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 19 13:41:58 PDT 2024


Author: Wentao Zhang
Date: 2024-06-19T15:41:55-05:00
New Revision: 61e62ce2ebde23937af3e4ca2d84195bb00dbe05

URL: https://github.com/llvm/llvm-project/commit/61e62ce2ebde23937af3e4ca2d84195bb00dbe05
DIFF: https://github.com/llvm/llvm-project/commit/61e62ce2ebde23937af3e4ca2d84195bb00dbe05.diff

LOG: [llvm-cov] let text mode divider honor --show-branch-summary, --show-region-summary etc (#96016)

Added: 
    

Modified: 
    llvm/tools/llvm-cov/CoverageReport.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-cov/CoverageReport.cpp b/llvm/tools/llvm-cov/CoverageReport.cpp
index 49a35f2a943e6..00aea4039bfde 100644
--- a/llvm/tools/llvm-cov/CoverageReport.cpp
+++ b/llvm/tools/llvm-cov/CoverageReport.cpp
@@ -102,8 +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) {
-  size_t Length = std::accumulate(ColumnWidths.begin(), ColumnWidths.end(), 0);
+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 << '-';
 }
@@ -405,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);
+    renderDivider(OS, Options, false);
     OS << "\n";
     FunctionCoverageSummary Totals("TOTAL");
     for (const auto &F : Functions) {
@@ -418,7 +435,7 @@ void CoverageReport::renderFunctionReports(ArrayRef<std::string> Files,
       render(Function, DC, OS);
     }
     if (Totals.ExecutionCount) {
-      renderDivider(FunctionReportColumns, OS);
+      renderDivider(OS, Options, false);
       OS << "\n";
       render(Totals, DC, OS);
     }
@@ -544,7 +561,7 @@ void CoverageReport::renderFileReports(
                  Column::RightAlignment)
        << column("Cover", FileReportColumns[18], Column::RightAlignment);
   OS << "\n";
-  renderDivider(FileReportColumns, OS);
+  renderDivider(OS, Options, true);
   OS << "\n";
 
   std::vector<const FileCoverageSummary *> EmptyFiles;
@@ -563,7 +580,7 @@ void CoverageReport::renderFileReports(
       render(*FCS, OS);
   }
 
-  renderDivider(FileReportColumns, OS);
+  renderDivider(OS, Options, true);
   OS << "\n";
   render(Totals, OS);
 }


        


More information about the llvm-commits mailing list