Skip to content

Commit c4ab7f0

Browse files
authored
Revert "[llvm-cov] Fix branch counts of template functions (#111743) (#113925)"
This reverts commit 0fe1f85.
1 parent 56cb5cb commit c4ab7f0

File tree

5 files changed

+32
-179
lines changed

5 files changed

+32
-179
lines changed

llvm/test/tools/llvm-cov/branch-export-lcov-unify-instances.test

Lines changed: 0 additions & 38 deletions
This file was deleted.

llvm/test/tools/llvm-cov/branch-export-lcov.test

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
// Check recursive macro-expansions.
4141
// RUN: llvm-profdata merge %S/Inputs/branch-macros.proftext -o %t.profdata
42-
// RUN: llvm-cov export --format=lcov --unify-instantiations=false %S/Inputs/branch-macros.o32l -instr-profile %t.profdata | FileCheck %s -check-prefix=MACROS
42+
// RUN: llvm-cov export --format=lcov %S/Inputs/branch-macros.o32l -instr-profile %t.profdata | FileCheck %s -check-prefix=MACROS
4343
// RUN: llvm-cov export --format=lcov --skip-branches %S/Inputs/branch-macros.o32l -instr-profile %t.profdata | FileCheck %s -check-prefix=NOBRANCH
4444

4545
// MACROS-COUNT-4: BRDA:17
@@ -78,38 +78,3 @@
7878
// NOBRANCH-NOT: BRF
7979
// NOBRANCH-NOT: BRH
8080

81-
// Check recursive macro-expansions with unify mode.
82-
// RUN: llvm-profdata merge %S/Inputs/branch-macros.proftext -o %t.profdata
83-
// RUN: llvm-cov export --format=lcov --unify-instantiations=true %S/Inputs/branch-macros.o32l -instr-profile %t.profdata | FileCheck %s -check-prefix=MACROS2
84-
85-
// MACROS2-COUNT-4: BRDA:17
86-
// MACROS2-NOT: BRDA:17
87-
88-
// MACROS2-COUNT-4: BRDA:19
89-
// MACROS2-NOT: BRDA:19
90-
91-
// MACROS2-COUNT-4: BRDA:21
92-
// MACROS2-NOT: BRDA:21
93-
94-
// MACROS2-COUNT-4: BRDA:23
95-
// MACROS2-NOT: BRDA:23
96-
97-
// MACROS2-COUNT-4: BRDA:25
98-
// MACROS2-NOT: BRDA:25
99-
100-
// MACROS2: BRDA:27,0,0,0
101-
// MACROS2: BRDA:27,0,1,3
102-
// MACROS2: BRDA:27,1,2,-
103-
// MACROS2: BRDA:27,1,3,-
104-
// MACROS2: BRDA:27,2,4,-
105-
// MACROS2: BRDA:27,2,5,-
106-
// MACROS2: BRDA:27,3,6,-
107-
// MACROS2: BRDA:27,3,7,-
108-
// MACROS2: BRDA:27,4,8,-
109-
// MACROS2: BRDA:27,4,9,-
110-
111-
// MACROS2-COUNT-10: BRDA:37
112-
// MACROS2-NOT: BRDA:37
113-
// MACROS2-NOT: BRDA
114-
// MACROS2: BRF:40
115-
// MACROS2: BRH:24

llvm/tools/llvm-cov/CodeCoverage.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,18 +1270,13 @@ int CodeCoverageTool::doExport(int argc, const char **argv,
12701270
cl::desc("Don't export branch data (LCOV)"),
12711271
cl::cat(ExportCategory));
12721272

1273-
cl::opt<bool> UnifyInstantiations("unify-instantiations", cl::Optional,
1274-
cl::desc("Unify function instantiations"),
1275-
cl::init(true), cl::cat(ExportCategory));
1276-
12771273
auto Err = commandLineParser(argc, argv);
12781274
if (Err)
12791275
return Err;
12801276

12811277
ViewOpts.SkipExpansions = SkipExpansions;
12821278
ViewOpts.SkipFunctions = SkipFunctions;
12831279
ViewOpts.SkipBranches = SkipBranches;
1284-
ViewOpts.UnifyFunctionInstantiations = UnifyInstantiations;
12851280

12861281
if (ViewOpts.Format != CoverageViewOptions::OutputFormat::Text &&
12871282
ViewOpts.Format != CoverageViewOptions::OutputFormat::Lcov) {

llvm/tools/llvm-cov/CoverageExporterLcov.cpp

Lines changed: 31 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,9 @@
4343
#include "CoverageReport.h"
4444

4545
using namespace llvm;
46-
using namespace coverage;
4746

4847
namespace {
4948

50-
struct NestedCountedRegion : public coverage::CountedRegion {
51-
// Contains the path to default and expanded branches.
52-
// Size is 1 for default branches and greater 1 for expanded branches.
53-
std::vector<LineColPair> NestedPath;
54-
// Indicates whether this item should be ignored at rendering.
55-
bool Ignore = false;
56-
57-
NestedCountedRegion(llvm::coverage::CountedRegion Region,
58-
std::vector<LineColPair> NestedPath)
59-
: llvm::coverage::CountedRegion(std::move(Region)),
60-
NestedPath(std::move(NestedPath)) {}
61-
62-
// Returns the root line of the branch.
63-
unsigned getEffectiveLine() const { return NestedPath.front().first; }
64-
};
65-
6649
void renderFunctionSummary(raw_ostream &OS,
6750
const FileCoverageSummary &Summary) {
6851
OS << "FNF:" << Summary.FunctionCoverage.getNumFunctions() << '\n'
@@ -92,121 +75,71 @@ void renderLineExecutionCounts(raw_ostream &OS,
9275
}
9376
}
9477

95-
std::vector<NestedCountedRegion>
78+
std::vector<llvm::coverage::CountedRegion>
9679
collectNestedBranches(const coverage::CoverageMapping &Coverage,
9780
ArrayRef<llvm::coverage::ExpansionRecord> Expansions,
98-
std::vector<LineColPair> &NestedPath) {
99-
std::vector<NestedCountedRegion> Branches;
81+
int ViewDepth = 0, int SrcLine = 0) {
82+
std::vector<llvm::coverage::CountedRegion> Branches;
10083
for (const auto &Expansion : Expansions) {
10184
auto ExpansionCoverage = Coverage.getCoverageForExpansion(Expansion);
10285

103-
// Track the path to the nested expansions.
104-
NestedPath.push_back(Expansion.Region.startLoc());
86+
// If we're at the top level, set the corresponding source line.
87+
if (ViewDepth == 0)
88+
SrcLine = Expansion.Region.LineStart;
10589

10690
// Recursively collect branches from nested expansions.
10791
auto NestedExpansions = ExpansionCoverage.getExpansions();
108-
auto NestedExBranches =
109-
collectNestedBranches(Coverage, NestedExpansions, NestedPath);
92+
auto NestedExBranches = collectNestedBranches(Coverage, NestedExpansions,
93+
ViewDepth + 1, SrcLine);
11094
append_range(Branches, NestedExBranches);
11195

11296
// Add branches from this level of expansion.
11397
auto ExBranches = ExpansionCoverage.getBranches();
114-
for (auto &B : ExBranches)
98+
for (auto B : ExBranches)
11599
if (B.FileID == Expansion.FileID) {
116-
Branches.push_back(NestedCountedRegion(B, NestedPath));
100+
B.LineStart = SrcLine;
101+
Branches.push_back(B);
117102
}
118-
119-
NestedPath.pop_back();
120103
}
121104

122105
return Branches;
123106
}
124107

125-
void appendNestedCountedRegions(const std::vector<CountedRegion> &Src,
126-
std::vector<NestedCountedRegion> &Dst) {
127-
auto Unfolded = make_filter_range(Src, [](auto &Region) {
128-
return !Region.TrueFolded || !Region.FalseFolded;
129-
});
130-
Dst.reserve(Dst.size() + Src.size());
131-
std::transform(Unfolded.begin(), Unfolded.end(), std::back_inserter(Dst),
132-
[=](auto &Region) {
133-
return NestedCountedRegion(Region, {Region.startLoc()});
134-
});
135-
}
136-
137-
void appendNestedCountedRegions(const std::vector<NestedCountedRegion> &Src,
138-
std::vector<NestedCountedRegion> &Dst) {
139-
auto Unfolded = make_filter_range(Src, [](auto &NestedRegion) {
140-
return !NestedRegion.TrueFolded || !NestedRegion.FalseFolded;
141-
});
142-
Dst.reserve(Dst.size() + Src.size());
143-
std::copy(Unfolded.begin(), Unfolded.end(), std::back_inserter(Dst));
144-
}
145-
146-
bool sortNested(const NestedCountedRegion &I, const NestedCountedRegion &J) {
147-
// This sorts each element by line and column.
148-
// Implies that all elements are first sorted by getEffectiveLine().
149-
return I.NestedPath < J.NestedPath;
150-
}
151-
152-
void combineInstanceCounts(std::vector<NestedCountedRegion> &Branches) {
153-
auto NextBranch = Branches.begin();
154-
auto EndBranch = Branches.end();
155-
156-
while (NextBranch != EndBranch) {
157-
auto SumBranch = NextBranch++;
158-
159-
// Ensure that only branches with the same NestedPath are summed up.
160-
while (NextBranch != EndBranch &&
161-
SumBranch->NestedPath == NextBranch->NestedPath) {
162-
SumBranch->ExecutionCount += NextBranch->ExecutionCount;
163-
SumBranch->FalseExecutionCount += NextBranch->FalseExecutionCount;
164-
// Mark this branch as ignored.
165-
NextBranch->Ignore = true;
166-
167-
NextBranch++;
168-
}
169-
}
108+
bool sortLine(llvm::coverage::CountedRegion I,
109+
llvm::coverage::CountedRegion J) {
110+
return (I.LineStart < J.LineStart) ||
111+
((I.LineStart == J.LineStart) && (I.ColumnStart < J.ColumnStart));
170112
}
171113

172114
void renderBranchExecutionCounts(raw_ostream &OS,
173115
const coverage::CoverageMapping &Coverage,
174-
const coverage::CoverageData &FileCoverage,
175-
bool UnifyInstances) {
176-
177-
std::vector<NestedCountedRegion> Branches;
178-
179-
appendNestedCountedRegions(FileCoverage.getBranches(), Branches);
116+
const coverage::CoverageData &FileCoverage) {
117+
std::vector<llvm::coverage::CountedRegion> Branches =
118+
FileCoverage.getBranches();
180119

181120
// Recursively collect branches for all file expansions.
182-
std::vector<LineColPair> NestedPath;
183-
std::vector<NestedCountedRegion> ExBranches =
184-
collectNestedBranches(Coverage, FileCoverage.getExpansions(), NestedPath);
121+
std::vector<llvm::coverage::CountedRegion> ExBranches =
122+
collectNestedBranches(Coverage, FileCoverage.getExpansions());
185123

186124
// Append Expansion Branches to Source Branches.
187-
appendNestedCountedRegions(ExBranches, Branches);
125+
append_range(Branches, ExBranches);
188126

189127
// Sort branches based on line number to ensure branches corresponding to the
190128
// same source line are counted together.
191-
llvm::sort(Branches, sortNested);
192-
193-
if (UnifyInstances) {
194-
combineInstanceCounts(Branches);
195-
}
129+
llvm::sort(Branches, sortLine);
196130

197131
auto NextBranch = Branches.begin();
198132
auto EndBranch = Branches.end();
199133

200134
// Branches with the same source line are enumerated individually
201135
// (BranchIndex) as well as based on True/False pairs (PairIndex).
202136
while (NextBranch != EndBranch) {
203-
unsigned CurrentLine = NextBranch->getEffectiveLine();
137+
unsigned CurrentLine = NextBranch->LineStart;
204138
unsigned PairIndex = 0;
205139
unsigned BranchIndex = 0;
206140

207-
while (NextBranch != EndBranch &&
208-
CurrentLine == NextBranch->getEffectiveLine()) {
209-
if (!NextBranch->Ignore) {
141+
while (NextBranch != EndBranch && CurrentLine == NextBranch->LineStart) {
142+
if (!NextBranch->TrueFolded || !NextBranch->FalseFolded) {
210143
unsigned BC1 = NextBranch->ExecutionCount;
211144
unsigned BC2 = NextBranch->FalseExecutionCount;
212145
bool BranchNotExecuted = (BC1 == 0 && BC2 == 0);
@@ -240,7 +173,7 @@ void renderBranchSummary(raw_ostream &OS, const FileCoverageSummary &Summary) {
240173
void renderFile(raw_ostream &OS, const coverage::CoverageMapping &Coverage,
241174
const std::string &Filename,
242175
const FileCoverageSummary &FileReport, bool ExportSummaryOnly,
243-
bool SkipFunctions, bool SkipBranches, bool UnifyInstances) {
176+
bool SkipFunctions, bool SkipBranches) {
244177
OS << "SF:" << Filename << '\n';
245178

246179
if (!ExportSummaryOnly && !SkipFunctions) {
@@ -253,7 +186,7 @@ void renderFile(raw_ostream &OS, const coverage::CoverageMapping &Coverage,
253186
auto FileCoverage = Coverage.getCoverageForFile(Filename);
254187
renderLineExecutionCounts(OS, FileCoverage);
255188
if (!SkipBranches)
256-
renderBranchExecutionCounts(OS, Coverage, FileCoverage, UnifyInstances);
189+
renderBranchExecutionCounts(OS, Coverage, FileCoverage);
257190
}
258191
if (!SkipBranches)
259192
renderBranchSummary(OS, FileReport);
@@ -265,11 +198,11 @@ void renderFile(raw_ostream &OS, const coverage::CoverageMapping &Coverage,
265198
void renderFiles(raw_ostream &OS, const coverage::CoverageMapping &Coverage,
266199
ArrayRef<std::string> SourceFiles,
267200
ArrayRef<FileCoverageSummary> FileReports,
268-
bool ExportSummaryOnly, bool SkipFunctions, bool SkipBranches,
269-
bool UnifyInstances) {
201+
bool ExportSummaryOnly, bool SkipFunctions,
202+
bool SkipBranches) {
270203
for (unsigned I = 0, E = SourceFiles.size(); I < E; ++I)
271204
renderFile(OS, Coverage, SourceFiles[I], FileReports[I], ExportSummaryOnly,
272-
SkipFunctions, SkipBranches, UnifyInstances);
205+
SkipFunctions, SkipBranches);
273206
}
274207

275208
} // end anonymous namespace
@@ -288,6 +221,5 @@ void CoverageExporterLcov::renderRoot(ArrayRef<std::string> SourceFiles) {
288221
auto FileReports = CoverageReport::prepareFileReports(Coverage, Totals,
289222
SourceFiles, Options);
290223
renderFiles(OS, Coverage, SourceFiles, FileReports, Options.ExportSummaryOnly,
291-
Options.SkipFunctions, Options.SkipBranches,
292-
Options.UnifyFunctionInstantiations);
224+
Options.SkipFunctions, Options.SkipBranches);
293225
}

llvm/tools/llvm-cov/CoverageViewOptions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ struct CoverageViewOptions {
3535
bool ShowBranchPercents;
3636
bool ShowExpandedRegions;
3737
bool ShowFunctionInstantiations;
38-
bool UnifyFunctionInstantiations;
3938
bool ShowFullFilenames;
4039
bool ShowBranchSummary;
4140
bool ShowMCDCSummary;

0 commit comments

Comments
 (0)