Skip to content

Commit

Permalink
[llvm-cov] Remove View member from MCDCView and BranchView (llvm#97734)
Browse files Browse the repository at this point in the history
These were never actually used, and the way they were constructed
doesn't really make sense.

Fixes llvm#93798.
  • Loading branch information
nikic committed Jul 5, 2024
1 parent c60b930 commit eb7ebd5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 54 deletions.
50 changes: 15 additions & 35 deletions llvm/tools/llvm-cov/CodeCoverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,12 @@ class CodeCoverageTool {
const CoverageMapping &Coverage);

/// Create source views for the branches of the view.
void attachBranchSubViews(SourceCoverageView &View, StringRef SourceName,
ArrayRef<CountedRegion> Branches,
const MemoryBuffer &File,
CoverageData &CoverageInfo);
void attachBranchSubViews(SourceCoverageView &View,
ArrayRef<CountedRegion> Branches);

/// Create source views for the MCDC records.
void attachMCDCSubViews(SourceCoverageView &View, StringRef SourceName,
ArrayRef<MCDCRecord> MCDCRecords,
const MemoryBuffer &File, CoverageData &CoverageInfo);
void attachMCDCSubViews(SourceCoverageView &View,
ArrayRef<MCDCRecord> MCDCRecords);

/// Create the source view of a particular function.
std::unique_ptr<SourceCoverageView>
Expand Down Expand Up @@ -324,17 +321,13 @@ void CodeCoverageTool::attachExpansionSubViews(
SourceCoverageView::create(Expansion.Function.Name, SourceBuffer.get(),
ViewOpts, std::move(ExpansionCoverage));
attachExpansionSubViews(*SubView, SubViewExpansions, Coverage);
attachBranchSubViews(*SubView, Expansion.Function.Name, SubViewBranches,
SourceBuffer.get(), ExpansionCoverage);
attachBranchSubViews(*SubView, SubViewBranches);
View.addExpansion(Expansion.Region, std::move(SubView));
}
}

void CodeCoverageTool::attachBranchSubViews(SourceCoverageView &View,
StringRef SourceName,
ArrayRef<CountedRegion> Branches,
const MemoryBuffer &File,
CoverageData &CoverageInfo) {
ArrayRef<CountedRegion> Branches) {
if (!ViewOpts.ShowBranchCounts && !ViewOpts.ShowBranchPercents)
return;

Expand All @@ -348,17 +341,12 @@ void CodeCoverageTool::attachBranchSubViews(SourceCoverageView &View,
while (NextBranch != EndBranch && CurrentLine == NextBranch->LineStart)
ViewBranches.push_back(*NextBranch++);

View.addBranch(CurrentLine, std::move(ViewBranches),
SourceCoverageView::create(SourceName, File, ViewOpts,
std::move(CoverageInfo)));
View.addBranch(CurrentLine, std::move(ViewBranches));
}
}

void CodeCoverageTool::attachMCDCSubViews(SourceCoverageView &View,
StringRef SourceName,
ArrayRef<MCDCRecord> MCDCRecords,
const MemoryBuffer &File,
CoverageData &CoverageInfo) {
ArrayRef<MCDCRecord> MCDCRecords) {
if (!ViewOpts.ShowMCDC)
return;

Expand All @@ -374,9 +362,7 @@ void CodeCoverageTool::attachMCDCSubViews(SourceCoverageView &View,
CurrentLine == NextRecord->getDecisionRegion().LineEnd)
ViewMCDCRecords.push_back(*NextRecord++);

View.addMCDCRecord(CurrentLine, std::move(ViewMCDCRecords),
SourceCoverageView::create(SourceName, File, ViewOpts,
std::move(CoverageInfo)));
View.addMCDCRecord(CurrentLine, std::move(ViewMCDCRecords));
}
}

Expand All @@ -397,10 +383,8 @@ CodeCoverageTool::createFunctionView(const FunctionRecord &Function,
SourceBuffer.get(), ViewOpts,
std::move(FunctionCoverage));
attachExpansionSubViews(*View, Expansions, Coverage);
attachBranchSubViews(*View, DC.demangle(Function.Name), Branches,
SourceBuffer.get(), FunctionCoverage);
attachMCDCSubViews(*View, DC.demangle(Function.Name), MCDCRecords,
SourceBuffer.get(), FunctionCoverage);
attachBranchSubViews(*View, Branches);
attachMCDCSubViews(*View, MCDCRecords);

return View;
}
Expand All @@ -421,10 +405,8 @@ CodeCoverageTool::createSourceFileView(StringRef SourceFile,
auto View = SourceCoverageView::create(SourceFile, SourceBuffer.get(),
ViewOpts, std::move(FileCoverage));
attachExpansionSubViews(*View, Expansions, Coverage);
attachBranchSubViews(*View, SourceFile, Branches, SourceBuffer.get(),
FileCoverage);
attachMCDCSubViews(*View, SourceFile, MCDCRecords, SourceBuffer.get(),
FileCoverage);
attachBranchSubViews(*View, Branches);
attachMCDCSubViews(*View, MCDCRecords);
if (!ViewOpts.ShowFunctionInstantiations)
return View;

Expand All @@ -446,10 +428,8 @@ CodeCoverageTool::createSourceFileView(StringRef SourceFile,
SubView = SourceCoverageView::create(
Funcname, SourceBuffer.get(), ViewOpts, std::move(SubViewCoverage));
attachExpansionSubViews(*SubView, SubViewExpansions, Coverage);
attachBranchSubViews(*SubView, SourceFile, SubViewBranches,
SourceBuffer.get(), SubViewCoverage);
attachMCDCSubViews(*SubView, SourceFile, SubViewMCDCRecords,
SourceBuffer.get(), SubViewCoverage);
attachBranchSubViews(*SubView, SubViewBranches);
attachMCDCSubViews(*SubView, SubViewMCDCRecords);
}

unsigned FileID = Function->CountedRegions.front().FileID;
Expand Down
12 changes: 5 additions & 7 deletions llvm/tools/llvm-cov/SourceCoverageView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,13 @@ void SourceCoverageView::addExpansion(
}

void SourceCoverageView::addBranch(unsigned Line,
SmallVector<CountedRegion, 0> Regions,
std::unique_ptr<SourceCoverageView> View) {
BranchSubViews.emplace_back(Line, std::move(Regions), std::move(View));
SmallVector<CountedRegion, 0> Regions) {
BranchSubViews.emplace_back(Line, std::move(Regions));
}

void SourceCoverageView::addMCDCRecord(
unsigned Line, SmallVector<MCDCRecord, 0> Records,
std::unique_ptr<SourceCoverageView> View) {
MCDCSubViews.emplace_back(Line, std::move(Records), std::move(View));
void SourceCoverageView::addMCDCRecord(unsigned Line,
SmallVector<MCDCRecord, 0> Records) {
MCDCSubViews.emplace_back(Line, std::move(Records));
}

void SourceCoverageView::addInstantiation(
Expand Down
18 changes: 6 additions & 12 deletions llvm/tools/llvm-cov/SourceCoverageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,10 @@ struct InstantiationView {
/// A view that represents one or more branch regions on a given source line.
struct BranchView {
SmallVector<CountedRegion, 0> Regions;
std::unique_ptr<SourceCoverageView> View;
unsigned Line;

BranchView(unsigned Line, SmallVector<CountedRegion, 0> Regions,
std::unique_ptr<SourceCoverageView> View)
: Regions(std::move(Regions)), View(std::move(View)), Line(Line) {}
BranchView(unsigned Line, SmallVector<CountedRegion, 0> Regions)
: Regions(std::move(Regions)), Line(Line) {}

unsigned getLine() const { return Line; }

Expand All @@ -87,12 +85,10 @@ struct BranchView {
/// A view that represents one or more MCDC regions on a given source line.
struct MCDCView {
SmallVector<MCDCRecord, 0> Records;
std::unique_ptr<SourceCoverageView> View;
unsigned Line;

MCDCView(unsigned Line, SmallVector<MCDCRecord, 0> Records,
std::unique_ptr<SourceCoverageView> View)
: Records(std::move(Records)), View(std::move(View)), Line(Line) {}
MCDCView(unsigned Line, SmallVector<MCDCRecord, 0> Records)
: Records(std::move(Records)), Line(Line) {}

unsigned getLine() const { return Line; }

Expand Down Expand Up @@ -303,12 +299,10 @@ class SourceCoverageView {
std::unique_ptr<SourceCoverageView> View);

/// Add a branch subview to this view.
void addBranch(unsigned Line, SmallVector<CountedRegion, 0> Regions,
std::unique_ptr<SourceCoverageView> View);
void addBranch(unsigned Line, SmallVector<CountedRegion, 0> Regions);

/// Add an MCDC subview to this view.
void addMCDCRecord(unsigned Line, SmallVector<MCDCRecord, 0> Records,
std::unique_ptr<SourceCoverageView> View);
void addMCDCRecord(unsigned Line, SmallVector<MCDCRecord, 0> Records);

/// Print the code coverage information for a specific portion of a
/// source file to the output stream.
Expand Down

0 comments on commit eb7ebd5

Please sign in to comment.