[llvm-branch-commits] [llvm] llvm-cov: Calculate RegionCoverage based on `CoverageData::Segments` (PR #121191)

NAKAMURA Takumi via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Dec 27 00:50:41 PST 2024


https://github.com/chapuni created https://github.com/llvm/llvm-project/pull/121191

None

>From 92bf1c1eeaa79a1f9a6d410744d38dd5bf342040 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Fri, 27 Dec 2024 15:44:28 +0900
Subject: [PATCH] llvm-cov: Emit RegionCoverage based on
 `CoverageData::Segments`

---
 llvm/test/tools/llvm-cov/branch-c-general.test   | 12 ++++++------
 llvm/test/tools/llvm-cov/branch-export-json.test |  2 +-
 llvm/test/tools/llvm-cov/branch-macros.test      |  6 +++---
 .../test/tools/llvm-cov/branch-noShowBranch.test | 12 ++++++------
 llvm/test/tools/llvm-cov/mcdc-general-none.test  |  6 +++---
 llvm/test/tools/llvm-cov/mcdc-general.test       |  6 +++---
 llvm/tools/llvm-cov/CoverageSummaryInfo.cpp      | 16 ++++++++--------
 llvm/tools/llvm-cov/CoverageSummaryInfo.h        |  3 +--
 8 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/llvm/test/tools/llvm-cov/branch-c-general.test b/llvm/test/tools/llvm-cov/branch-c-general.test
index 3c163bf6de45cc..9ee15ec75428e5 100644
--- a/llvm/test/tools/llvm-cov/branch-c-general.test
+++ b/llvm/test/tools/llvm-cov/branch-c-general.test
@@ -117,19 +117,19 @@
 // REPORT:      Name                        Regions    Miss   Cover     Lines    Miss   Cover  Branches    Miss   Cover
 // REPORT-NEXT: ---
 // REPORT-NEXT: simple_loops                      8       0 100.00%         9       0 100.00%         6       0 100.00%
-// REPORT-NEXT: conditionals                     24       0 100.00%        15       0 100.00%        16       2  87.50%
+// REPORT-NEXT: conditionals                     22       0 100.00%        15       0 100.00%        16       2  87.50%
 // REPORT-NEXT: early_exits                      20       4  80.00%        25       2  92.00%        16       6  62.50%
 // REPORT-NEXT: jumps                            39      12  69.23%        48       2  95.83%        26       9  65.38%
-// REPORT-NEXT: switches                         28       5  82.14%        38       4  89.47%        28       7  75.00%
+// REPORT-NEXT: switches                         27       4  85.19%        38       4  89.47%        28       7  75.00%
 // REPORT-NEXT: big_switch                       25       1  96.00%        32       0 100.00%        30       6  80.00%
-// REPORT-NEXT: boolean_operators                16       0 100.00%        13       0 100.00%        22       2  90.91%
-// REPORT-NEXT: boolop_loops                     19       0 100.00%        14       0 100.00%        16       2  87.50%
+// REPORT-NEXT: boolean_operators                14       0 100.00%        13       0 100.00%        22       2  90.91%
+// REPORT-NEXT: boolop_loops                     15       0 100.00%        14       0 100.00%        16       2  87.50%
 // REPORT-NEXT: conditional_operator              4       2  50.00%         8       0 100.00%         4       2  50.00%
 // REPORT-NEXT: do_fallthrough                    9       0 100.00%        12       0 100.00%         6       0 100.00%
 // REPORT-NEXT: main                              1       0 100.00%        16       0 100.00%         0       0   0.00%
 // REPORT-NEXT: c-general.c:static_func           4       0 100.00%         4       0 100.00%         2       0 100.00%
 // REPORT-NEXT: ---
-// REPORT-NEXT: TOTAL                           197      24  87.82%       234       8  96.58%       172      36  79.07%
+// REPORT-NEXT: TOTAL                           188      23  87.77%       234       8  96.58%       172      36  79.07%
 
 // Test file-level report.
 // RUN: llvm-profdata merge %S/Inputs/branch-c-general.proftext -o %t.profdata
@@ -159,7 +159,7 @@
 // HTML-INDEX: <td class='column-entry-yellow'>
 // HTML-INDEX: 96.58% (226/234)
 // HTML-INDEX: <td class='column-entry-yellow'>
-// HTML-INDEX: 87.82% (173/197)
+// HTML-INDEX: 87.77% (165/188)
 // HTML-INDEX: <td class='column-entry-red'>
 // HTML-INDEX: 79.07% (136/172)
 // HTML-INDEX: <tr class='light-row-bold'>
diff --git a/llvm/test/tools/llvm-cov/branch-export-json.test b/llvm/test/tools/llvm-cov/branch-export-json.test
index 7cf42860879827..4278482c6d870e 100644
--- a/llvm/test/tools/llvm-cov/branch-export-json.test
+++ b/llvm/test/tools/llvm-cov/branch-export-json.test
@@ -18,7 +18,7 @@
 // CHECK: 45,5,45,11,0,5,0,0,4
 // CHECK: 47,5,47,12,3,2,0,0,4
 // CHECK: 53,12,53,20,50,5,0,0,4
-// CHECK: {"count":30,"covered":26,"notcovered":4,"percent":86.666666666666671}
+// CHECK: {"count":30,"covered":26,"notcovered":4,"percent":86.6[[#]]}
 
 // Check recursive macro-expansions.
 // RUN: llvm-profdata merge %S/Inputs/branch-macros.proftext -o %t.profdata
diff --git a/llvm/test/tools/llvm-cov/branch-macros.test b/llvm/test/tools/llvm-cov/branch-macros.test
index e4bd14ec14f16c..b3b163f5457b03 100644
--- a/llvm/test/tools/llvm-cov/branch-macros.test
+++ b/llvm/test/tools/llvm-cov/branch-macros.test
@@ -8,8 +8,8 @@
 
 // REPORT:      Name                        Regions    Miss   Cover     Lines    Miss   Cover  Branches    Miss   Cover
 // REPORT-NEXT: ---
-// REPORT-NEXT: _Z4funcii                        28       4  85.71%        18       0 100.00%        30      14  53.33%
-// REPORT-NEXT: _Z5func2ii                       13       1  92.31%         8       0 100.00%        10       2  80.00%
+// REPORT-NEXT: _Z4funcii                        12       4  66.67%        18       0 100.00%        30      14  53.33%
+// REPORT-NEXT: _Z5func2ii                        3       0 100.00%         8       0 100.00%        10       2  80.00%
 // REPORT-NEXT: main                              1       0 100.00%         6       0 100.00%         0       0   0.00%
 // REPORT-NEXT: ---
-// REPORT-NEXT: TOTAL                            42       5  88.10%        32       0 100.00%        40      16  60.00%
+// REPORT-NEXT: TOTAL                            16       4  75.00%        32       0 100.00%        40      16  60.00%
diff --git a/llvm/test/tools/llvm-cov/branch-noShowBranch.test b/llvm/test/tools/llvm-cov/branch-noShowBranch.test
index 9f3cfd55f029b5..11a9a5a665b70e 100644
--- a/llvm/test/tools/llvm-cov/branch-noShowBranch.test
+++ b/llvm/test/tools/llvm-cov/branch-noShowBranch.test
@@ -9,16 +9,16 @@
 // REPORT-NOT: Name                        Regions    Miss   Cover     Lines    Miss   Cover  Branches    Miss   Cover
 // REPORT:     ---
 // REPORT-NOT: simple_loops                      8       0 100.00%         9       0 100.00%         6       0 100.00%
-// REPORT-NOT: conditionals                     24       0 100.00%        15       0 100.00%        16       2  87.50%
+// REPORT-NOT: conditionals                     22       0 100.00%        15       0 100.00%        16       2  87.50%
 // REPORT-NOT: early_exits                      20       4  80.00%        25       2  92.00%        16       6  62.50%
 // REPORT-NOT: jumps                            39      12  69.23%        48       2  95.83%        26       9  65.38%
-// REPORT-NOT: switches                         28       5  82.14%        38       4  89.47%        28       7  75.00%
+// REPORT-NOT: switches                         27       4  85.19%        38       4  89.47%        28       7  75.00%
 // REPORT-NOT: big_switch                       25       1  96.00%        32       0 100.00%        30       6  80.00%
-// REPORT-NOT: boolean_operators                16       0 100.00%        13       0 100.00%        22       2  90.91%
-// REPORT-NOT: boolop_loops                     19       0 100.00%        14       0 100.00%        16       2  87.50%
+// REPORT-NOT: boolean_operators                14       0 100.00%        13       0 100.00%        22       2  90.91%
+// REPORT-NOT: boolop_loops                     15       0 100.00%        14       0 100.00%        16       2  87.50%
 // REPORT-NOT: conditional_operator              4       2  50.00%         8       0 100.00%         4       2  50.00%
 // REPORT-NOT: do_fallthrough                    9       0 100.00%        12       0 100.00%         6       0 100.00%
 // REPORT-NOT: main                              1       0 100.00%        16       0 100.00%         0       0   0.00%
 // REPORT-NOT: c-general.c:static_func           4       0 100.00%         4       0 100.00%         2       0 100.00%
-// REPORT:     TOTAL                           197      24  87.82%       234       8  96.58%
-// REPORT-NOT: TOTAL                           197      24  87.82%       234       8  96.58%       172      36  79.07%
+// REPORT:     TOTAL                           188      23  87.77%       234       8  96.58%
+// REPORT-NOT: TOTAL                           188      23  87.77%       234       8  96.58%       172      36  79.07%
diff --git a/llvm/test/tools/llvm-cov/mcdc-general-none.test b/llvm/test/tools/llvm-cov/mcdc-general-none.test
index b57b35d49c8c11..db95314ac950ab 100644
--- a/llvm/test/tools/llvm-cov/mcdc-general-none.test
+++ b/llvm/test/tools/llvm-cov/mcdc-general-none.test
@@ -34,10 +34,10 @@
 
 //      REPORT: Name                        Regions    Miss   Cover     Lines    Miss   Cover  Branches    Miss   Cover    MC/DC Conditions    Miss   Cover
 // REPORT-NEXT: -------------------------------------------------------------------------------------------------------------------------------------------
-// REPORT-NEXT: _Z4testbbbb                      25       0 100.00%         9       0 100.00%        24       2  91.67%                  12      12   0.00%
+// REPORT-NEXT: _Z4testbbbb                      21       0 100.00%         9       0 100.00%        24       2  91.67%                  12      12   0.00%
 // REPORT-NEXT: main                              1       0 100.00%        11       0 100.00%         0       0   0.00%                   0       0   0.00%
 // REPORT-NEXT: ---
-// REPORT-NEXT: TOTAL                            26       0 100.00%        20       0 100.00%        24       2  91.67%                  12      12   0.00%
+// REPORT-NEXT: TOTAL                            22       0 100.00%        20       0 100.00%        24       2  91.67%                  12      12   0.00%
 
 // Turn off MC/DC summary.
 // RUN: llvm-cov report %S/Inputs/mcdc-general.o -instr-profile %t.profdata -show-functions -path-equivalence=.,%S/Inputs %S/Inputs/mcdc-general.cpp | FileCheck %s -check-prefix=REPORT_NOMCDC
@@ -67,7 +67,7 @@
 // HTML-INDEX: <td class='column-entry-green'>
 // HTML-INDEX: 100.00% (2/2)
 // HTML-INDEX: 100.00% (20/20)
-// HTML-INDEX: 100.00% (26/26)
+// HTML-INDEX: 100.00% (22/22)
 // HTML-INDEX: 91.67% (22/24)
 // HTML-INDEX: 0.00% (0/12)
 // HTML-INDEX: Totals
diff --git a/llvm/test/tools/llvm-cov/mcdc-general.test b/llvm/test/tools/llvm-cov/mcdc-general.test
index c1e95cb2bd92ac..7ae9e180c00c29 100644
--- a/llvm/test/tools/llvm-cov/mcdc-general.test
+++ b/llvm/test/tools/llvm-cov/mcdc-general.test
@@ -100,10 +100,10 @@
 
 //      REPORT: Name                        Regions    Miss   Cover     Lines    Miss   Cover  Branches    Miss   Cover    MC/DC Conditions    Miss   Cover
 // REPORT-NEXT: -------------------------------------------------------------------------------------------------------------------------------------------
-// REPORT-NEXT: _Z4testbbbb                      25       0 100.00%         9       0 100.00%        24       2  91.67%                  12       2  83.33%
+// REPORT-NEXT: _Z4testbbbb                      21       0 100.00%         9       0 100.00%        24       2  91.67%                  12       2  83.33%
 // REPORT-NEXT: main                              1       0 100.00%        11       0 100.00%         0       0   0.00%                   0       0   0.00%
 // REPORT-NEXT: ---
-// REPORT-NEXT: TOTAL                            26       0 100.00%        20       0 100.00%        24       2  91.67%                  12       2  83.33%
+// REPORT-NEXT: TOTAL                            22       0 100.00%        20       0 100.00%        24       2  91.67%                  12       2  83.33%
 
 // Turn off MC/DC summary.
 // RUN: llvm-cov report %S/Inputs/mcdc-general.o -instr-profile %t.profdata -show-functions -path-equivalence=.,%S/Inputs %S/Inputs/mcdc-general.cpp | FileCheck %s -check-prefix=REPORT_NOMCDC
@@ -133,7 +133,7 @@
 // HTML-INDEX: <td class='column-entry-green'>
 // HTML-INDEX: 100.00% (2/2)
 // HTML-INDEX: 100.00% (20/20)
-// HTML-INDEX: 100.00% (26/26)
+// HTML-INDEX: 100.00% (22/22)
 // HTML-INDEX: 91.67% (22/24)
 // HTML-INDEX: 83.33% (10/12)
 // HTML-INDEX: Totals
diff --git a/llvm/tools/llvm-cov/CoverageSummaryInfo.cpp b/llvm/tools/llvm-cov/CoverageSummaryInfo.cpp
index 5c002a694f66ae..86d11266ecdd7c 100644
--- a/llvm/tools/llvm-cov/CoverageSummaryInfo.cpp
+++ b/llvm/tools/llvm-cov/CoverageSummaryInfo.cpp
@@ -63,14 +63,15 @@ auto sumMCDCPairs(const ArrayRef<MCDCRecord> &Records) {
 }
 
 static std::pair<RegionCoverageInfo, LineCoverageInfo>
-sumRegions(ArrayRef<CountedRegion> CodeRegions, const CoverageData &CD) {
+sumRegions(const CoverageData &CD) {
   // Compute the region coverage.
   size_t NumCodeRegions = 0, CoveredRegions = 0;
-  for (auto &CR : CodeRegions) {
-    if (CR.Kind != CounterMappingRegion::CodeRegion)
+  for (auto I = CD.begin(), E = CD.end(); I != E; ++I) {
+    if (!I->IsRegionEntry || !I->HasCount || I->IsGapRegion)
       continue;
+
     ++NumCodeRegions;
-    if (CR.ExecutionCount != 0)
+    if (I->Count)
       ++CoveredRegions;
   }
 
@@ -88,9 +89,8 @@ sumRegions(ArrayRef<CountedRegion> CodeRegions, const CoverageData &CD) {
           LineCoverageInfo(CoveredLines, NumLines)};
 }
 
-CoverageDataSummary::CoverageDataSummary(const CoverageData &CD,
-                                         ArrayRef<CountedRegion> CodeRegions) {
-  std::tie(RegionCoverage, LineCoverage) = sumRegions(CodeRegions, CD);
+CoverageDataSummary::CoverageDataSummary(const CoverageData &CD) {
+  std::tie(RegionCoverage, LineCoverage) = sumRegions(CD);
   BranchCoverage = sumBranches(CD.getBranches());
   MCDCCoverage = sumMCDCPairs(CD.getMCDCRecords());
 }
@@ -103,7 +103,7 @@ FunctionCoverageSummary::get(const CoverageMapping &CM,
   auto Summary =
       FunctionCoverageSummary(Function.Name, Function.ExecutionCount);
 
-  Summary += CoverageDataSummary(CD, Function.CountedRegions);
+  Summary += CoverageDataSummary(CD);
 
   // Compute the branch coverage, including branches from expansions.
   Summary.BranchCoverage += sumBranchExpansions(CM, CD.getExpansions());
diff --git a/llvm/tools/llvm-cov/CoverageSummaryInfo.h b/llvm/tools/llvm-cov/CoverageSummaryInfo.h
index d9210676c41bf3..42398ee06100e2 100644
--- a/llvm/tools/llvm-cov/CoverageSummaryInfo.h
+++ b/llvm/tools/llvm-cov/CoverageSummaryInfo.h
@@ -230,8 +230,7 @@ struct CoverageDataSummary {
   MCDCCoverageInfo MCDCCoverage;
 
   CoverageDataSummary() = default;
-  CoverageDataSummary(const coverage::CoverageData &CD,
-                      ArrayRef<coverage::CountedRegion> CodeRegions);
+  CoverageDataSummary(const coverage::CoverageData &CD);
 
   auto &operator+=(const CoverageDataSummary &RHS) {
     RegionCoverage += RHS.RegionCoverage;



More information about the llvm-branch-commits mailing list