From 0a7576bf1345af03f2dd986fda09d4542d5f8b87 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 4 Jul 2024 16:22:42 +0200 Subject: [PATCH] [llvm-cov] Remove View member from MCDCView and BranchView These were never actually used, and the way they were constructed doesn't really make sense. Fixes https://github.com/llvm/llvm-project/issues/93798. --- llvm/tools/llvm-cov/CodeCoverage.cpp | 50 +++++++--------------- llvm/tools/llvm-cov/SourceCoverageView.cpp | 12 +++--- llvm/tools/llvm-cov/SourceCoverageView.h | 18 +++----- 3 files changed, 26 insertions(+), 54 deletions(-) diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp index 75028ac0bb505..d06fd86fe52af 100644 --- a/llvm/tools/llvm-cov/CodeCoverage.cpp +++ b/llvm/tools/llvm-cov/CodeCoverage.cpp @@ -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 Branches, - const MemoryBuffer &File, - CoverageData &CoverageInfo); + void attachBranchSubViews(SourceCoverageView &View, + ArrayRef Branches); /// Create source views for the MCDC records. - void attachMCDCSubViews(SourceCoverageView &View, StringRef SourceName, - ArrayRef MCDCRecords, - const MemoryBuffer &File, CoverageData &CoverageInfo); + void attachMCDCSubViews(SourceCoverageView &View, + ArrayRef MCDCRecords); /// Create the source view of a particular function. std::unique_ptr @@ -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 Branches, - const MemoryBuffer &File, - CoverageData &CoverageInfo) { + ArrayRef Branches) { if (!ViewOpts.ShowBranchCounts && !ViewOpts.ShowBranchPercents) return; @@ -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 MCDCRecords, - const MemoryBuffer &File, - CoverageData &CoverageInfo) { + ArrayRef MCDCRecords) { if (!ViewOpts.ShowMCDC) return; @@ -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)); } } @@ -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; } @@ -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; @@ -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; diff --git a/llvm/tools/llvm-cov/SourceCoverageView.cpp b/llvm/tools/llvm-cov/SourceCoverageView.cpp index ce55e3abf23bd..dfecddfaf4143 100644 --- a/llvm/tools/llvm-cov/SourceCoverageView.cpp +++ b/llvm/tools/llvm-cov/SourceCoverageView.cpp @@ -175,15 +175,13 @@ void SourceCoverageView::addExpansion( } void SourceCoverageView::addBranch(unsigned Line, - SmallVector Regions, - std::unique_ptr View) { - BranchSubViews.emplace_back(Line, std::move(Regions), std::move(View)); + SmallVector Regions) { + BranchSubViews.emplace_back(Line, std::move(Regions)); } -void SourceCoverageView::addMCDCRecord( - unsigned Line, SmallVector Records, - std::unique_ptr View) { - MCDCSubViews.emplace_back(Line, std::move(Records), std::move(View)); +void SourceCoverageView::addMCDCRecord(unsigned Line, + SmallVector Records) { + MCDCSubViews.emplace_back(Line, std::move(Records)); } void SourceCoverageView::addInstantiation( diff --git a/llvm/tools/llvm-cov/SourceCoverageView.h b/llvm/tools/llvm-cov/SourceCoverageView.h index d255f8c200b24..2b1570d399dd0 100644 --- a/llvm/tools/llvm-cov/SourceCoverageView.h +++ b/llvm/tools/llvm-cov/SourceCoverageView.h @@ -70,12 +70,10 @@ struct InstantiationView { /// A view that represents one or more branch regions on a given source line. struct BranchView { SmallVector Regions; - std::unique_ptr View; unsigned Line; - BranchView(unsigned Line, SmallVector Regions, - std::unique_ptr View) - : Regions(std::move(Regions)), View(std::move(View)), Line(Line) {} + BranchView(unsigned Line, SmallVector Regions) + : Regions(std::move(Regions)), Line(Line) {} unsigned getLine() const { return Line; } @@ -87,12 +85,10 @@ struct BranchView { /// A view that represents one or more MCDC regions on a given source line. struct MCDCView { SmallVector Records; - std::unique_ptr View; unsigned Line; - MCDCView(unsigned Line, SmallVector Records, - std::unique_ptr View) - : Records(std::move(Records)), View(std::move(View)), Line(Line) {} + MCDCView(unsigned Line, SmallVector Records) + : Records(std::move(Records)), Line(Line) {} unsigned getLine() const { return Line; } @@ -303,12 +299,10 @@ class SourceCoverageView { std::unique_ptr View); /// Add a branch subview to this view. - void addBranch(unsigned Line, SmallVector Regions, - std::unique_ptr View); + void addBranch(unsigned Line, SmallVector Regions); /// Add an MCDC subview to this view. - void addMCDCRecord(unsigned Line, SmallVector Records, - std::unique_ptr View); + void addMCDCRecord(unsigned Line, SmallVector Records); /// Print the code coverage information for a specific portion of a /// source file to the output stream.