diff options
Diffstat (limited to 'llvm/tools/llvm-cov')
-rw-r--r-- | llvm/tools/llvm-cov/CodeCoverage.cpp | 36 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/CoverageExporterJson.cpp | 19 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/CoverageExporterLcov.cpp | 14 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/CoverageFilters.cpp | 1 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/CoverageFilters.h | 10 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/CoverageReport.cpp | 16 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/CoverageSummaryInfo.cpp | 2 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/SourceCoverageView.cpp | 4 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp | 11 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/gcov.cpp | 28 |
10 files changed, 84 insertions, 57 deletions
diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp index 5f1e23f20d772..b3c895b44a6d6 100644 --- a/llvm/tools/llvm-cov/CodeCoverage.cpp +++ b/llvm/tools/llvm-cov/CodeCoverage.cpp @@ -33,6 +33,7 @@ #include "llvm/Support/Process.h" #include "llvm/Support/Program.h" #include "llvm/Support/ScopedPrinter.h" +#include "llvm/Support/SpecialCaseList.h" #include "llvm/Support/ThreadPool.h" #include "llvm/Support/Threading.h" #include "llvm/Support/ToolOutputFile.h" @@ -245,7 +246,8 @@ CodeCoverageTool::getSourceFile(StringRef SourceFile) { error(EC.message(), SourceFile); return EC; } - LoadedSourceFiles.emplace_back(SourceFile, std::move(Buffer.get())); + LoadedSourceFiles.emplace_back(std::string(SourceFile), + std::move(Buffer.get())); return *LoadedSourceFiles.back().second; } @@ -413,7 +415,8 @@ void CodeCoverageTool::remapPathNames(const CoverageMapping &Coverage) { // Convert input files from local paths to coverage data file paths. StringMap<std::string> InvRemappedFilenames; for (const auto &RemappedFilename : RemappedFilenames) - InvRemappedFilenames[RemappedFilename.getValue()] = RemappedFilename.getKey(); + InvRemappedFilenames[RemappedFilename.getValue()] = + std::string(RemappedFilename.getKey()); for (std::string &Filename : SourceFiles) { SmallString<128> NativeFilename; @@ -510,7 +513,7 @@ void CodeCoverageTool::demangleSymbols(const CoverageMapping &Coverage) { for (const auto &Function : Coverage.getCoveredFunctions()) // On Windows, lines in the demangler's output file end with "\r\n". // Splitting by '\n' keeps '\r's, so cut them now. - DC.DemangledNames[Function.Name] = Symbols[I++].rtrim(); + DC.DemangledNames[Function.Name] = std::string(Symbols[I++].rtrim()); } void CodeCoverageTool::writeSourceFileView(StringRef SourceFile, @@ -688,7 +691,8 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { // PathRemapping. auto EquivPair = StringRef(PathRemap).split(','); if (!(EquivPair.first.empty() && EquivPair.second.empty())) - PathRemapping = EquivPair; + PathRemapping = {std::string(EquivPair.first), + std::string(EquivPair.second)}; // If a demangler is supplied, check if it exists and register it. if (!DemanglerOpts.empty()) { @@ -864,8 +868,8 @@ int CodeCoverageTool::doShow(int argc, const char **argv, } sys::fs::file_status Status; - if (sys::fs::status(PGOFilename, Status)) { - error("profdata file error: can not get the file status. \n"); + if (std::error_code EC = sys::fs::status(PGOFilename, Status)) { + error("Could not read profile data!", EC.message()); return 1; } @@ -886,7 +890,7 @@ int CodeCoverageTool::doShow(int argc, const char **argv, // Get the source files from the function coverage mapping. for (StringRef Filename : Coverage->getUniqueSourceFiles()) { if (!IgnoreFilenameFilters.matchesFilename(Filename)) - SourceFiles.push_back(Filename); + SourceFiles.push_back(std::string(Filename)); } // Create an index out of the source files. @@ -940,21 +944,21 @@ int CodeCoverageTool::doShow(int argc, const char **argv, (SourceFiles.size() != 1) || ViewOpts.hasOutputDirectory() || (ViewOpts.Format == CoverageViewOptions::OutputFormat::HTML); - auto NumThreads = ViewOpts.NumThreads; - - // If NumThreads is not specified, auto-detect a good default. - if (NumThreads == 0) - NumThreads = - std::max(1U, std::min(llvm::heavyweight_hardware_concurrency(), - unsigned(SourceFiles.size()))); + ThreadPoolStrategy S = hardware_concurrency(ViewOpts.NumThreads); + if (ViewOpts.NumThreads == 0) { + // If NumThreads is not specified, create one thread for each input, up to + // the number of hardware cores. + S = heavyweight_hardware_concurrency(SourceFiles.size()); + S.Limit = true; + } - if (!ViewOpts.hasOutputDirectory() || NumThreads == 1) { + if (!ViewOpts.hasOutputDirectory() || S.ThreadsRequested == 1) { for (const std::string &SourceFile : SourceFiles) writeSourceFileView(SourceFile, Coverage.get(), Printer.get(), ShowFilenames); } else { // In -output-dir mode, it's safe to use multiple threads to print files. - ThreadPool Pool(NumThreads); + ThreadPool Pool(S); for (const std::string &SourceFile : SourceFiles) Pool.async(&CodeCoverageTool::writeSourceFileView, this, SourceFile, Coverage.get(), Printer.get(), ShowFilenames); diff --git a/llvm/tools/llvm-cov/CoverageExporterJson.cpp b/llvm/tools/llvm-cov/CoverageExporterJson.cpp index 216b5e3fd2263..c8bb1aa5b6ea6 100644 --- a/llvm/tools/llvm-cov/CoverageExporterJson.cpp +++ b/llvm/tools/llvm-cov/CoverageExporterJson.cpp @@ -53,7 +53,7 @@ #include <utility> /// The semantic version combined as a string. -#define LLVM_COVERAGE_EXPORT_JSON_STR "2.0.0" +#define LLVM_COVERAGE_EXPORT_JSON_STR "2.0.1" /// Unique type identifier for JSON coverage export. #define LLVM_COVERAGE_EXPORT_JSON_TYPE_STR "llvm.coverage.json.export" @@ -72,8 +72,9 @@ int64_t clamp_uint64_to_int64(uint64_t u) { } json::Array renderSegment(const coverage::CoverageSegment &Segment) { - return json::Array({Segment.Line, Segment.Col, clamp_uint64_to_int64(Segment.Count), - Segment.HasCount, Segment.IsRegionEntry}); + return json::Array({Segment.Line, Segment.Col, + clamp_uint64_to_int64(Segment.Count), Segment.HasCount, + Segment.IsRegionEntry, Segment.IsGapRegion}); } json::Array renderRegion(const coverage::CountedRegion &Region) { @@ -162,12 +163,14 @@ json::Array renderFiles(const coverage::CoverageMapping &Coverage, ArrayRef<std::string> SourceFiles, ArrayRef<FileCoverageSummary> FileReports, const CoverageViewOptions &Options) { - auto NumThreads = Options.NumThreads; - if (NumThreads == 0) { - NumThreads = std::max(1U, std::min(llvm::heavyweight_hardware_concurrency(), - unsigned(SourceFiles.size()))); + ThreadPoolStrategy S = hardware_concurrency(Options.NumThreads); + if (Options.NumThreads == 0) { + // If NumThreads is not specified, create one thread for each input, up to + // the number of hardware cores. + S = heavyweight_hardware_concurrency(SourceFiles.size()); + S.Limit = true; } - ThreadPool Pool(NumThreads); + ThreadPool Pool(S); json::Array FileArray; std::mutex FileArrayMutex; diff --git a/llvm/tools/llvm-cov/CoverageExporterLcov.cpp b/llvm/tools/llvm-cov/CoverageExporterLcov.cpp index d9b0c3b0d7a88..a6b3c66070304 100644 --- a/llvm/tools/llvm-cov/CoverageExporterLcov.cpp +++ b/llvm/tools/llvm-cov/CoverageExporterLcov.cpp @@ -78,10 +78,11 @@ void renderLineSummary(raw_ostream &OS, const FileCoverageSummary &Summary) { void renderFile(raw_ostream &OS, const coverage::CoverageMapping &Coverage, const std::string &Filename, - const FileCoverageSummary &FileReport, bool ExportSummaryOnly) { + const FileCoverageSummary &FileReport, bool ExportSummaryOnly, + bool SkipFunctions) { OS << "SF:" << Filename << '\n'; - if (!ExportSummaryOnly) { + if (!ExportSummaryOnly && !SkipFunctions) { renderFunctions(OS, Coverage.getCoveredFunctions(Filename)); } renderFunctionSummary(OS, FileReport); @@ -99,9 +100,10 @@ void renderFile(raw_ostream &OS, const coverage::CoverageMapping &Coverage, void renderFiles(raw_ostream &OS, const coverage::CoverageMapping &Coverage, ArrayRef<std::string> SourceFiles, ArrayRef<FileCoverageSummary> FileReports, - bool ExportSummaryOnly) { + bool ExportSummaryOnly, bool SkipFunctions) { for (unsigned I = 0, E = SourceFiles.size(); I < E; ++I) - renderFile(OS, Coverage, SourceFiles[I], FileReports[I], ExportSummaryOnly); + renderFile(OS, Coverage, SourceFiles[I], FileReports[I], ExportSummaryOnly, + SkipFunctions); } } // end anonymous namespace @@ -119,6 +121,6 @@ void CoverageExporterLcov::renderRoot(ArrayRef<std::string> SourceFiles) { FileCoverageSummary Totals = FileCoverageSummary("Totals"); auto FileReports = CoverageReport::prepareFileReports(Coverage, Totals, SourceFiles, Options); - renderFiles(OS, Coverage, SourceFiles, FileReports, - Options.ExportSummaryOnly); + renderFiles(OS, Coverage, SourceFiles, FileReports, Options.ExportSummaryOnly, + Options.SkipFunctions); } diff --git a/llvm/tools/llvm-cov/CoverageFilters.cpp b/llvm/tools/llvm-cov/CoverageFilters.cpp index ca241e386e87e..da3b5214eec4c 100644 --- a/llvm/tools/llvm-cov/CoverageFilters.cpp +++ b/llvm/tools/llvm-cov/CoverageFilters.cpp @@ -13,6 +13,7 @@ #include "CoverageFilters.h" #include "CoverageSummaryInfo.h" #include "llvm/Support/Regex.h" +#include "llvm/Support/SpecialCaseList.h" using namespace llvm; diff --git a/llvm/tools/llvm-cov/CoverageFilters.h b/llvm/tools/llvm-cov/CoverageFilters.h index ce56e16071117..33fd9929c59a2 100644 --- a/llvm/tools/llvm-cov/CoverageFilters.h +++ b/llvm/tools/llvm-cov/CoverageFilters.h @@ -13,13 +13,17 @@ #ifndef LLVM_COV_COVERAGEFILTERS_H #define LLVM_COV_COVERAGEFILTERS_H -#include "CoverageSummaryInfo.h" -#include "llvm/ProfileData/Coverage/CoverageMapping.h" -#include "llvm/Support/SpecialCaseList.h" +#include "llvm/ADT/StringRef.h" #include <memory> #include <vector> namespace llvm { +class SpecialCaseList; + +namespace coverage { +class CoverageMapping; +struct FunctionRecord; +} // namespace coverage /// Matches specific functions that pass the requirement of this filter. class CoverageFilter { diff --git a/llvm/tools/llvm-cov/CoverageReport.cpp b/llvm/tools/llvm-cov/CoverageReport.cpp index 82259542c5970..8509710032d15 100644 --- a/llvm/tools/llvm-cov/CoverageReport.cpp +++ b/llvm/tools/llvm-cov/CoverageReport.cpp @@ -352,15 +352,15 @@ std::vector<FileCoverageSummary> CoverageReport::prepareFileReports( ArrayRef<std::string> Files, const CoverageViewOptions &Options, const CoverageFilter &Filters) { unsigned LCP = getRedundantPrefixLen(Files); - auto NumThreads = Options.NumThreads; - // If NumThreads is not specified, auto-detect a good default. - if (NumThreads == 0) - NumThreads = - std::max(1U, std::min(llvm::heavyweight_hardware_concurrency(), - unsigned(Files.size()))); - - ThreadPool Pool(NumThreads); + ThreadPoolStrategy S = hardware_concurrency(Options.NumThreads); + if (Options.NumThreads == 0) { + // If NumThreads is not specified, create one thread for each input, up to + // the number of hardware cores. + S = heavyweight_hardware_concurrency(Files.size()); + S.Limit = true; + } + ThreadPool Pool(S); std::vector<FileCoverageSummary> FileReports; FileReports.reserve(Files.size()); diff --git a/llvm/tools/llvm-cov/CoverageSummaryInfo.cpp b/llvm/tools/llvm-cov/CoverageSummaryInfo.cpp index 1029f7784040d..929529c27b6ea 100644 --- a/llvm/tools/llvm-cov/CoverageSummaryInfo.cpp +++ b/llvm/tools/llvm-cov/CoverageSummaryInfo.cpp @@ -51,7 +51,7 @@ FunctionCoverageSummary::get(const InstantiationGroup &Group, ArrayRef<FunctionCoverageSummary> Summaries) { std::string Name; if (Group.hasName()) { - Name = Group.getName(); + Name = std::string(Group.getName()); } else { llvm::raw_string_ostream OS(Name); OS << "Definition at line " << Group.getLine() << ", column " diff --git a/llvm/tools/llvm-cov/SourceCoverageView.cpp b/llvm/tools/llvm-cov/SourceCoverageView.cpp index 0e20ea63cd6ff..cd7395a1a87d3 100644 --- a/llvm/tools/llvm-cov/SourceCoverageView.cpp +++ b/llvm/tools/llvm-cov/SourceCoverageView.cpp @@ -48,7 +48,7 @@ std::string CoveragePrinter::getOutputPath(StringRef Path, StringRef Extension, sys::path::append(FullPath, PathFilename); sys::path::native(FullPath); - return FullPath.str(); + return std::string(FullPath.str()); } Expected<CoveragePrinter::OwnedStream> @@ -158,7 +158,7 @@ std::string SourceCoverageView::getSourceName() const { SmallString<128> SourceText(SourceName); sys::path::remove_dots(SourceText, /*remove_dot_dots=*/true); sys::path::native(SourceText); - return SourceText.str(); + return std::string(SourceText.str()); } void SourceCoverageView::addExpansion( diff --git a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp index e3332245f9c8e..9d10def0a211b 100644 --- a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp +++ b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp @@ -30,8 +30,7 @@ std::string escape(StringRef Str, const CoverageViewOptions &Opts) { if (C == '\t') { // Replace '\t' with up to TabSize spaces. unsigned NumSpaces = Opts.TabSize - (ColNum % Opts.TabSize); - for (unsigned I = 0; I < NumSpaces; ++I) - TabExpandedResult += ' '; + TabExpandedResult.append(NumSpaces, ' '); ColNum += NumSpaces; } else { TabExpandedResult += C; @@ -250,7 +249,7 @@ const char *CreatedTimeTag = "h4"; std::string getPathToStyle(StringRef ViewPath) { std::string PathToStyle = ""; - std::string PathSep = sys::path::get_separator(); + std::string PathSep = std::string(sys::path::get_separator()); unsigned NumSeps = ViewPath.count(PathSep); for (unsigned I = 0, E = NumSeps; I < E; ++I) PathToStyle += ".." + PathSep; @@ -359,7 +358,7 @@ void CoveragePrinterHTML::emitFileSummary(raw_ostream &OS, StringRef SF, // Simplify the display file path, and wrap it in a link if requested. std::string Filename; if (IsTotals) { - Filename = SF; + Filename = std::string(SF); } else { Filename = buildLinkToFile(SF, FCS); } @@ -507,7 +506,7 @@ void SourceCoverageViewHTML::renderLine(raw_ostream &OS, LineRef L, unsigned LCol = 1; auto Snip = [&](unsigned Start, unsigned Len) { - Snippets.push_back(Line.substr(Start, Len)); + Snippets.push_back(std::string(Line.substr(Start, Len))); LCol += Len; }; @@ -533,7 +532,7 @@ void SourceCoverageViewHTML::renderLine(raw_ostream &OS, LineRef L, auto Highlight = [&](const std::string &Snippet, unsigned LC, unsigned RC) { if (getOptions().Debug) HighlightedRanges.emplace_back(LC, RC); - return tag("span", Snippet, Color.getValue()); + return tag("span", Snippet, std::string(Color.getValue())); }; auto CheckIfUncovered = [&](const CoverageSegment *S) { diff --git a/llvm/tools/llvm-cov/gcov.cpp b/llvm/tools/llvm-cov/gcov.cpp index 8a00ff64711fb..7a1dbbfe9338b 100644 --- a/llvm/tools/llvm-cov/gcov.cpp +++ b/llvm/tools/llvm-cov/gcov.cpp @@ -65,11 +65,11 @@ static void reportCoverage(StringRef SourceFile, StringRef ObjectDir, // Clear the filename to make it clear we didn't read anything. GCDA = "-"; } else { - GCOVBuffer GCDA_GB(GCDA_Buff.get().get()); - if (!GF.readGCDA(GCDA_GB)) { + GCOVBuffer gcda_buf(GCDA_Buff.get().get()); + if (!gcda_buf.readGCDAFormat()) + errs() << GCDA << ":not a gcov data file\n"; + else if (!GF.readGCDA(gcda_buf)) errs() << "Invalid .gcda File!\n"; - return; - } } if (DumpGCOV) @@ -77,7 +77,7 @@ static void reportCoverage(StringRef SourceFile, StringRef ObjectDir, FileInfo FI(Options); GF.collectLineCounts(FI); - FI.print(llvm::outs(), SourceFile, GCNO, GCDA); + FI.print(llvm::outs(), SourceFile, GCNO, GCDA, GF); } int gcovMain(int argc, const char *argv[]) { @@ -105,6 +105,16 @@ int gcovMain(int argc, const char *argv[]) { cl::desc("Show coverage for each function")); cl::alias FuncSummaryA("function-summaries", cl::aliasopt(FuncSummary)); + // Supported by gcov 4.9~8. gcov 9 (GCC r265587) removed --intermediate-format + // and -i was changed to mean --json-format. We consider this format still + // useful and support -i. + cl::opt<bool> Intermediate( + "intermediate-format", cl::init(false), + cl::desc("Output .gcov in intermediate text format")); + cl::alias IntermediateA("i", cl::desc("Alias for --intermediate-format"), + cl::Grouping, cl::NotHidden, + cl::aliasopt(Intermediate)); + cl::opt<bool> NoOutput("n", cl::Grouping, cl::init(false), cl::desc("Do not output any .gcov files")); cl::alias NoOutputA("no-output", cl::aliasopt(NoOutput)); @@ -119,6 +129,10 @@ int gcovMain(int argc, const char *argv[]) { cl::desc("Preserve path components")); cl::alias PreservePathsA("preserve-paths", cl::aliasopt(PreservePaths)); + cl::opt<bool> UseStdout("t", cl::Grouping, cl::init(false), + cl::desc("Print to stdout")); + cl::alias UseStdoutA("stdout", cl::aliasopt(UseStdout)); + cl::opt<bool> UncondBranch("u", cl::Grouping, cl::init(false), cl::desc("Display unconditional branch info " "(requires -b)")); @@ -140,8 +154,8 @@ int gcovMain(int argc, const char *argv[]) { cl::ParseCommandLineOptions(argc, argv, "LLVM code coverage tool\n"); GCOV::Options Options(AllBlocks, BranchProb, BranchCount, FuncSummary, - PreservePaths, UncondBranch, LongNames, NoOutput, - HashFilenames); + PreservePaths, UncondBranch, Intermediate, LongNames, + NoOutput, UseStdout, HashFilenames); for (const auto &SourceFile : SourceFiles) reportCoverage(SourceFile, ObjectDir, InputGCNO, InputGCDA, DumpGCOV, |