Skip to content

Commit fed4134

Browse files
committed
Revert "Revert "[Coverage] Fix branch coverage merging in FunctionCoverageSummary::get() for instantiation""
This reverts commit 33d312b. The original patch was correct, so we need to restore it in the release branch.
1 parent b7c7b42 commit fed4134

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

llvm/test/tools/llvm-cov/branch-templates.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// RUN: llvm-profdata merge %S/Inputs/branch-templates.proftext -o %t.profdata
22
// RUN: llvm-cov show --show-expansions --show-branches=count %S/Inputs/branch-templates.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S %s | FileCheck %s
33
// RUN: llvm-cov report --show-branch-summary %S/Inputs/branch-templates.o32l -instr-profile %t.profdata -show-functions -path-equivalence=/tmp,%S %s | FileCheck %s -check-prefix=REPORT
4+
// RUN: llvm-cov report --show-branch-summary %S/Inputs/branch-templates.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S %s | FileCheck %s -check-prefix=REPORTFILE
45

56
#include <stdio.h>
6-
77
template<typename T>
88
void unused(T x) {
99
return;
@@ -45,3 +45,17 @@ int main() {
4545
// REPORT-NEXT: _Z4funcIfEiT_ 5 2 60.00% 7 3 57.14% 2 1 50.00%
4646
// REPORT-NEXT: ---
4747
// REPORT-NEXT: TOTAL 22 7 68.18% 31 11 64.52% 12 6 50.00%
48+
49+
// Make sure the covered branch tally for the function instantiation group is
50+
// merged to reflect maximum branch coverage of a single instantiation, just
51+
// like what is done for lines and regions. Also, the total branch tally
52+
// summary for an instantiation group should agree with the total number of
53+
// branches in the definition (In this case, 2 and 6 for func<>() and main(),
54+
// respectively). This is returned by: FunctionCoverageSummary::get(const
55+
// InstantiationGroup &Group, ...)
56+
57+
// REPORTFILE: Filename Regions Missed Regions Cover Functions Missed Functions Executed Lines Missed Lines Cover Branches Missed Branches Cover
58+
// REPORTFILE-NEXT: ---
59+
// REPORTFILE-NEXT: branch-templates.cpp 12 3 75.00% 2 0 100.00% 17 4 76.47% 8 4 50.00%
60+
// REPORTFILE-NEXT: ---
61+
// REPORTFILE-NEXT: TOTAL 12 3 75.00% 2 0 100.00% 17 4 76.47% 8 4 50.00%

llvm/tools/llvm-cov/CoverageSummaryInfo.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,7 @@ FunctionCoverageSummary::get(const InstantiationGroup &Group,
100100
for (const auto &FCS : Summaries.drop_front()) {
101101
Summary.RegionCoverage.merge(FCS.RegionCoverage);
102102
Summary.LineCoverage.merge(FCS.LineCoverage);
103-
104-
// Sum branch coverage across instantiation groups for the summary rather
105-
// than "merge" the maximum count. This is a clearer view into whether all
106-
// created branches are covered.
107-
Summary.BranchCoverage += FCS.BranchCoverage;
103+
Summary.BranchCoverage.merge(FCS.BranchCoverage);
108104
}
109105
return Summary;
110106
}

llvm/tools/llvm-cov/CoverageSummaryInfo.h

+5
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ class BranchCoverageInfo {
123123
return *this;
124124
}
125125

126+
void merge(const BranchCoverageInfo &RHS) {
127+
Covered = std::max(Covered, RHS.Covered);
128+
NumBranches = std::max(NumBranches, RHS.NumBranches);
129+
}
130+
126131
size_t getCovered() const { return Covered; }
127132

128133
size_t getNumBranches() const { return NumBranches; }

0 commit comments

Comments
 (0)