@@ -51,13 +51,16 @@ struct NestedCountedRegion : public coverage::CountedRegion {
51
51
// Contains the path to default and expanded branches.
52
52
// Size is 1 for default branches and greater 1 for expanded branches.
53
53
std::vector<LineColPair> NestedPath;
54
+ // Contains the original index of this element used to keep the original order
55
+ // in case of equal nested path.
56
+ unsigned Position;
54
57
// Indicates whether this item should be ignored at rendering.
55
58
bool Ignore = false ;
56
59
57
60
NestedCountedRegion (llvm::coverage::CountedRegion Region,
58
- std::vector<LineColPair> NestedPath)
61
+ std::vector<LineColPair> NestedPath, unsigned Position )
59
62
: llvm::coverage::CountedRegion(std::move(Region)),
60
- NestedPath (std::move(NestedPath)) {}
63
+ NestedPath (std::move(NestedPath)), Position(Position) {}
61
64
62
65
// Returns the root line of the branch.
63
66
unsigned getEffectiveLine () const { return NestedPath.front ().first ; }
@@ -95,7 +98,8 @@ void renderLineExecutionCounts(raw_ostream &OS,
95
98
std::vector<NestedCountedRegion>
96
99
collectNestedBranches (const coverage::CoverageMapping &Coverage,
97
100
ArrayRef<llvm::coverage::ExpansionRecord> Expansions,
98
- std::vector<LineColPair> &NestedPath) {
101
+ std::vector<LineColPair> &NestedPath,
102
+ unsigned &PositionCounter) {
99
103
std::vector<NestedCountedRegion> Branches;
100
104
for (const auto &Expansion : Expansions) {
101
105
auto ExpansionCoverage = Coverage.getCoverageForExpansion (Expansion);
@@ -105,15 +109,16 @@ collectNestedBranches(const coverage::CoverageMapping &Coverage,
105
109
106
110
// Recursively collect branches from nested expansions.
107
111
auto NestedExpansions = ExpansionCoverage.getExpansions ();
108
- auto NestedExBranches =
109
- collectNestedBranches (Coverage, NestedExpansions, NestedPath);
112
+ auto NestedExBranches = collectNestedBranches (Coverage, NestedExpansions,
113
+ NestedPath, PositionCounter );
110
114
append_range (Branches, NestedExBranches);
111
115
112
116
// Add branches from this level of expansion.
113
117
auto ExBranches = ExpansionCoverage.getBranches ();
114
118
for (auto &B : ExBranches)
115
119
if (B.FileID == Expansion.FileID ) {
116
- Branches.push_back (NestedCountedRegion (B, NestedPath));
120
+ Branches.push_back (
121
+ NestedCountedRegion (B, NestedPath, PositionCounter++));
117
122
}
118
123
119
124
NestedPath.pop_back ();
@@ -128,9 +133,11 @@ void appendNestedCountedRegions(const std::vector<CountedRegion> &Src,
128
133
return !Region.TrueFolded || !Region.FalseFolded ;
129
134
});
130
135
Dst.reserve (Dst.size () + Src.size ());
136
+ unsigned PositionCounter = Dst.size ();
131
137
std::transform (Unfolded.begin (), Unfolded.end (), std::back_inserter (Dst),
132
- [=](auto &Region) {
133
- return NestedCountedRegion (Region, {Region.startLoc ()});
138
+ [=, &PositionCounter](auto &Region) {
139
+ return NestedCountedRegion (Region, {Region.startLoc ()},
140
+ PositionCounter++);
134
141
});
135
142
}
136
143
@@ -143,10 +150,18 @@ void appendNestedCountedRegions(const std::vector<NestedCountedRegion> &Src,
143
150
std::copy (Unfolded.begin (), Unfolded.end (), std::back_inserter (Dst));
144
151
}
145
152
153
+ bool sortLine (const llvm::coverage::CountedRegion &I,
154
+ const llvm::coverage::CountedRegion &J) {
155
+ return (I.LineStart < J.LineStart ) ||
156
+ ((I.LineStart == J.LineStart ) && (I.ColumnStart < J.ColumnStart ));
157
+ }
158
+
146
159
bool sortNested (const NestedCountedRegion &I, const NestedCountedRegion &J) {
147
160
// This sorts each element by line and column.
148
161
// Implies that all elements are first sorted by getEffectiveLine().
149
- return I.NestedPath < J.NestedPath ;
162
+ // Use original position if NestedPath is equal.
163
+ return std::tie (I.NestedPath , I.Position ) <
164
+ std::tie (J.NestedPath , J.Position );
150
165
}
151
166
152
167
void combineInstanceCounts (std::vector<NestedCountedRegion> &Branches) {
@@ -180,8 +195,9 @@ void renderBranchExecutionCounts(raw_ostream &OS,
180
195
181
196
// Recursively collect branches for all file expansions.
182
197
std::vector<LineColPair> NestedPath;
183
- std::vector<NestedCountedRegion> ExBranches =
184
- collectNestedBranches (Coverage, FileCoverage.getExpansions (), NestedPath);
198
+ unsigned PositionCounter = 0 ;
199
+ std::vector<NestedCountedRegion> ExBranches = collectNestedBranches (
200
+ Coverage, FileCoverage.getExpansions (), NestedPath, PositionCounter);
185
201
186
202
// Append Expansion Branches to Source Branches.
187
203
appendNestedCountedRegions (ExBranches, Branches);
0 commit comments