Skip to content

llvm-cov: Calculate RegionCoverage based on CoverageData::Segments #121191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
12 changes: 6 additions & 6 deletions llvm/test/tools/llvm-cov/branch-c-general.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'>
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-cov/branch-export-json.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions llvm/test/tools/llvm-cov/branch-macros.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,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%
12 changes: 6 additions & 6 deletions llvm/test/tools/llvm-cov/branch-noShowBranch.test
Original file line number Diff line number Diff line change
Expand Up @@ -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%
6 changes: 3 additions & 3 deletions llvm/test/tools/llvm-cov/mcdc-general-none.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions llvm/test/tools/llvm-cov/mcdc-general.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions llvm/tools/llvm-cov/CoverageSummaryInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not possible to keep this as a range-based for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Iterators (for protected:Segments) are provided by CoverageData. I think range is less suitable here.

if (!I->IsRegionEntry || !I->HasCount || I->IsGapRegion)
continue;

++NumCodeRegions;
if (CR.ExecutionCount != 0)
if (I->Count)
++CoveredRegions;
}

Expand All @@ -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());
}
Expand All @@ -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());
Expand Down
3 changes: 1 addition & 2 deletions llvm/tools/llvm-cov/CoverageSummaryInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading