diff options
| author | Justin Bogner <mail@justinbogner.com> | 2015-02-14 02:01:24 +0000 |
|---|---|---|
| committer | Justin Bogner <mail@justinbogner.com> | 2015-02-14 02:01:24 +0000 |
| commit | f91bc6cdd87556fecc68cb95693fc0e37a15231a (patch) | |
| tree | cde984d2621589e809cc4f3c266053828890d22f /llvm/tools/llvm-cov/CoverageReport.cpp | |
| parent | 5975a703e6657784339e25fcf84a745e9342668a (diff) | |
| download | bcm5719-llvm-f91bc6cdd87556fecc68cb95693fc0e37a15231a.tar.gz bcm5719-llvm-f91bc6cdd87556fecc68cb95693fc0e37a15231a.zip | |
llvm-cov: Simplify coverage reports, fixing PR22575 in the process
PR22575 occurred because we were unsafely storing references into a
std::vector. If the vector moved because it grew, we'd be left
iterating through garbage memory. This avoids the issue by simplifying
the logic to gather coverage information as we go, rather than storing
it and iterating over it.
I'm relying on the existing tests showing that this is semantically
NFC, since it's difficult to hit the issue this fixes without
relatively large covered programs.
llvm-svn: 229215
Diffstat (limited to 'llvm/tools/llvm-cov/CoverageReport.cpp')
| -rw-r--r-- | llvm/tools/llvm-cov/CoverageReport.cpp | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/llvm/tools/llvm-cov/CoverageReport.cpp b/llvm/tools/llvm-cov/CoverageReport.cpp index 6ae6ba55eb9..db0754268c3 100644 --- a/llvm/tools/llvm-cov/CoverageReport.cpp +++ b/llvm/tools/llvm-cov/CoverageReport.cpp @@ -12,7 +12,6 @@ //===----------------------------------------------------------------------===// #include "CoverageReport.h" -#include "CoverageSummary.h" #include "RenderingSupport.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Format.h" @@ -158,12 +157,12 @@ void CoverageReport::render(const FunctionCoverageSummary &Function, void CoverageReport::renderFunctionReports(raw_ostream &OS) { bool isFirst = true; - for (const auto &File : Summary.getFileSummaries()) { + for (StringRef Filename : Coverage->getUniqueSourceFiles()) { if (isFirst) isFirst = false; else OS << "\n"; - OS << "File '" << File.Name << "':\n"; + OS << "File '" << Filename << "':\n"; OS << column("Name", FunctionReportColumns[0]) << column("Regions", FunctionReportColumns[1], Column::RightAlignment) << column("Miss", FunctionReportColumns[2], Column::RightAlignment) @@ -174,13 +173,19 @@ void CoverageReport::renderFunctionReports(raw_ostream &OS) { OS << "\n"; renderDivider(FunctionReportColumns, OS); OS << "\n"; - for (const auto &Function : File.FunctionSummaries) + FunctionCoverageSummary Totals("TOTAL"); + for (const auto &F : Coverage->getCoveredFunctions(Filename)) { + FunctionCoverageSummary Function = FunctionCoverageSummary::get(F); + ++Totals.ExecutionCount; + Totals.RegionCoverage += Function.RegionCoverage; + Totals.LineCoverage += Function.LineCoverage; render(Function, OS); - renderDivider(FunctionReportColumns, OS); - OS << "\n"; - render(FunctionCoverageSummary("TOTAL", /*ExecutionCount=*/0, - File.RegionCoverage, File.LineCoverage), - OS); + } + if (Totals.ExecutionCount) { + renderDivider(FunctionReportColumns, OS); + OS << "\n"; + render(Totals, OS); + } } } @@ -194,9 +199,17 @@ void CoverageReport::renderFileReports(raw_ostream &OS) { << "\n"; renderDivider(FileReportColumns, OS); OS << "\n"; - for (const auto &File : Summary.getFileSummaries()) - render(File, OS); + FileCoverageSummary Totals("TOTAL"); + for (StringRef Filename : Coverage->getUniqueSourceFiles()) { + FileCoverageSummary Summary(Filename); + for (const auto &F : Coverage->getCoveredFunctions(Filename)) { + FunctionCoverageSummary Function = FunctionCoverageSummary::get(F); + Summary.addFunction(Function); + Totals.addFunction(Function); + } + render(Summary, OS); + } renderDivider(FileReportColumns, OS); OS << "\n"; - render(Summary.getCombinedFileSummaries(), OS); + render(Totals, OS); } |

