summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-cov/CoverageSummary.cpp
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2015-02-14 02:01:24 +0000
committerJustin Bogner <mail@justinbogner.com>2015-02-14 02:01:24 +0000
commitf91bc6cdd87556fecc68cb95693fc0e37a15231a (patch)
treecde984d2621589e809cc4f3c266053828890d22f /llvm/tools/llvm-cov/CoverageSummary.cpp
parent5975a703e6657784339e25fcf84a745e9342668a (diff)
downloadbcm5719-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/CoverageSummary.cpp')
-rw-r--r--llvm/tools/llvm-cov/CoverageSummary.cpp64
1 files changed, 0 insertions, 64 deletions
diff --git a/llvm/tools/llvm-cov/CoverageSummary.cpp b/llvm/tools/llvm-cov/CoverageSummary.cpp
deleted file mode 100644
index 059c8c857e4..00000000000
--- a/llvm/tools/llvm-cov/CoverageSummary.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-//===- CoverageSummary.cpp - Code coverage summary ------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This class implements data management and rendering for the code coverage
-// summaries of all files and functions.
-//
-//===----------------------------------------------------------------------===//
-
-#include "CoverageSummary.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/Format.h"
-
-using namespace llvm;
-
-unsigned CoverageSummary::getFileID(StringRef Filename) {
- for (unsigned I = 0, E = Filenames.size(); I < E; ++I) {
- if (sys::fs::equivalent(Filenames[I], Filename))
- return I;
- }
- Filenames.push_back(Filename);
- return Filenames.size() - 1;
-}
-
-void
-CoverageSummary::createSummaries(const coverage::CoverageMapping &Coverage) {
- for (StringRef Filename : Coverage.getUniqueSourceFiles()) {
- size_t PrevSize = FunctionSummaries.size();
- for (const auto &F : Coverage.getCoveredFunctions(Filename))
- FunctionSummaries.push_back(FunctionCoverageSummary::get(F));
- size_t Count = FunctionSummaries.size() - PrevSize;
- if (Count == 0)
- continue;
- FileSummaries.push_back(FileCoverageSummary::get(
- Filename, makeArrayRef(FunctionSummaries.data() + PrevSize, Count)));
- }
-}
-
-FileCoverageSummary CoverageSummary::getCombinedFileSummaries() {
- size_t NumRegions = 0, CoveredRegions = 0;
- size_t NumLines = 0, NonCodeLines = 0, CoveredLines = 0;
- size_t NumFunctionsExecuted = 0, NumFunctions = 0;
- for (const auto &File : FileSummaries) {
- NumRegions += File.RegionCoverage.NumRegions;
- CoveredRegions += File.RegionCoverage.Covered;
-
- NumLines += File.LineCoverage.NumLines;
- NonCodeLines += File.LineCoverage.NonCodeLines;
- CoveredLines += File.LineCoverage.Covered;
-
- NumFunctionsExecuted += File.FunctionCoverage.Executed;
- NumFunctions += File.FunctionCoverage.NumFunctions;
- }
- return FileCoverageSummary(
- "TOTAL", RegionCoverageInfo(CoveredRegions, NumRegions),
- LineCoverageInfo(CoveredLines, NonCodeLines, NumLines),
- FunctionCoverageInfo(NumFunctionsExecuted, NumFunctions),
- None);
-}
OpenPOWER on IntegriCloud