16
16
using namespace llvm ;
17
17
using namespace coverage ;
18
18
19
- static void sumBranches (size_t &NumBranches, size_t &CoveredBranches,
20
- const ArrayRef<CountedRegion> &Branches) {
19
+ static auto sumBranches (const ArrayRef<CountedRegion> &Branches) {
20
+ size_t NumBranches = 0 ;
21
+ size_t CoveredBranches = 0 ;
21
22
for (const auto &BR : Branches) {
22
23
if (!BR.TrueFolded ) {
23
24
// "True" Condition Branches.
@@ -32,20 +33,22 @@ static void sumBranches(size_t &NumBranches, size_t &CoveredBranches,
32
33
++CoveredBranches;
33
34
}
34
35
}
36
+ return BranchCoverageInfo (CoveredBranches, NumBranches);
35
37
}
36
38
37
- static void sumBranchExpansions (size_t &NumBranches, size_t &CoveredBranches,
38
- const CoverageMapping &CM,
39
- ArrayRef<ExpansionRecord> Expansions) {
39
+ static BranchCoverageInfo
40
+ sumBranchExpansions (const CoverageMapping &CM,
41
+ ArrayRef<ExpansionRecord> Expansions) {
42
+ BranchCoverageInfo BranchCoverage;
40
43
for (const auto &Expansion : Expansions) {
41
44
auto CE = CM.getCoverageForExpansion (Expansion);
42
- sumBranches (NumBranches, CoveredBranches, CE.getBranches ());
43
- sumBranchExpansions (NumBranches, CoveredBranches, CM, CE.getExpansions ());
45
+ BranchCoverage += sumBranches ( CE.getBranches ());
46
+ BranchCoverage += sumBranchExpansions ( CM, CE.getExpansions ());
44
47
}
48
+ return BranchCoverage;
45
49
}
46
50
47
- static std::pair<size_t , size_t >
48
- sumMCDCPairs (const ArrayRef<MCDCRecord> &Records) {
51
+ auto sumMCDCPairs (const ArrayRef<MCDCRecord> &Records) {
49
52
size_t NumPairs = 0 , CoveredPairs = 0 ;
50
53
for (const auto &Record : Records) {
51
54
const auto NumConditions = Record.getNumConditions ();
@@ -56,7 +59,7 @@ sumMCDCPairs(const ArrayRef<MCDCRecord> &Records) {
56
59
++CoveredPairs;
57
60
}
58
61
}
59
- return {NumPairs, CoveredPairs} ;
62
+ return MCDCCoverageInfo (CoveredPairs, NumPairs) ;
60
63
}
61
64
62
65
static std::pair<RegionCoverageInfo, LineCoverageInfo>
@@ -85,24 +88,27 @@ sumRegions(ArrayRef<CountedRegion> CodeRegions, const CoverageData &CD) {
85
88
LineCoverageInfo (CoveredLines, NumLines)};
86
89
}
87
90
91
+ CoverageDataSummary::CoverageDataSummary (const CoverageData &CD,
92
+ ArrayRef<CountedRegion> CodeRegions) {
93
+ std::tie (RegionCoverage, LineCoverage) = sumRegions (CodeRegions, CD);
94
+ BranchCoverage = sumBranches (CD.getBranches ());
95
+ MCDCCoverage = sumMCDCPairs (CD.getMCDCRecords ());
96
+ }
97
+
88
98
FunctionCoverageSummary
89
99
FunctionCoverageSummary::get (const CoverageMapping &CM,
90
100
const coverage::FunctionRecord &Function) {
91
101
CoverageData CD = CM.getCoverageForFunction (Function);
92
- auto [RegionCoverage, LineCoverage] = sumRegions (Function.CountedRegions , CD);
93
102
94
- // Compute the branch coverage, including branches from expansions.
95
- size_t NumBranches = 0 , CoveredBranches = 0 ;
96
- sumBranches (NumBranches, CoveredBranches, CD.getBranches ());
97
- sumBranchExpansions (NumBranches, CoveredBranches, CM, CD.getExpansions ());
103
+ auto Summary =
104
+ FunctionCoverageSummary (Function.Name , Function.ExecutionCount );
98
105
99
- size_t NumPairs = 0 , CoveredPairs = 0 ;
100
- std::tie (NumPairs, CoveredPairs) = sumMCDCPairs (CD.getMCDCRecords ());
106
+ Summary += CoverageDataSummary (CD, Function.CountedRegions );
101
107
102
- return FunctionCoverageSummary (
103
- Function. Name , Function. ExecutionCount , RegionCoverage, LineCoverage,
104
- BranchCoverageInfo (CoveredBranches, NumBranches),
105
- MCDCCoverageInfo (CoveredPairs, NumPairs)) ;
108
+ // Compute the branch coverage, including branches from expansions.
109
+ Summary. BranchCoverage += sumBranchExpansions (CM, CD. getExpansions ());
110
+
111
+ return Summary ;
106
112
}
107
113
108
114
FunctionCoverageSummary
@@ -117,8 +123,7 @@ FunctionCoverageSummary::get(const InstantiationGroup &Group,
117
123
<< Group.getColumn ();
118
124
}
119
125
120
- FunctionCoverageSummary Summary (Name);
121
- Summary.ExecutionCount = Group.getTotalExecutionCount ();
126
+ FunctionCoverageSummary Summary (Name, Group.getTotalExecutionCount ());
122
127
Summary.RegionCoverage = Summaries[0 ].RegionCoverage ;
123
128
Summary.LineCoverage = Summaries[0 ].LineCoverage ;
124
129
Summary.BranchCoverage = Summaries[0 ].BranchCoverage ;
0 commit comments