From e3b557809604d036af6e00c60f012c2025b59a5e Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 11 Feb 2023 13:38:04 +0100 Subject: Vendor import of llvm-project main llvmorg-16-init-18548-gb0daacf58f41, the last commit before the upstream release/17.x branch was created. --- llvm/tools/llvm-cov/CodeCoverage.cpp | 67 ++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 38 deletions(-) (limited to 'llvm/tools/llvm-cov/CodeCoverage.cpp') diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp index 13b6c3002216..2b2eda5d8587 100644 --- a/llvm/tools/llvm-cov/CodeCoverage.cpp +++ b/llvm/tools/llvm-cov/CodeCoverage.cpp @@ -41,6 +41,7 @@ #include #include +#include #include using namespace llvm; @@ -84,7 +85,7 @@ private: bool isEquivalentFile(StringRef FilePath1, StringRef FilePath2); /// Retrieve a file status with a cache. - Optional getFileStatus(StringRef FilePath); + std::optional getFileStatus(StringRef FilePath); /// Return a memory buffer for the given source file. ErrorOr getSourceFile(StringRef SourceFile); @@ -157,10 +158,10 @@ private: /// The coverage data path to be remapped from, and the source path to be /// remapped to, when using -path-equivalence. - Optional> PathRemapping; + std::optional> PathRemapping; /// File status cache used when finding the same file. - StringMap> FileStatusCache; + StringMap> FileStatusCache; /// The architecture the coverage mapping data targets. std::vector CoverageArches; @@ -248,7 +249,7 @@ void CodeCoverageTool::collectPaths(const std::string &Path) { } } -Optional +std::optional CodeCoverageTool::getFileStatus(StringRef FilePath) { auto It = FileStatusCache.try_emplace(FilePath); auto &CachedStatus = It.first->getValue(); @@ -553,13 +554,16 @@ void CodeCoverageTool::demangleSymbols(const CoverageMapping &Coverage) { // Invoke the demangler. std::vector ArgsV; + ArgsV.reserve(ViewOpts.DemanglerOpts.size()); for (StringRef Arg : ViewOpts.DemanglerOpts) ArgsV.push_back(Arg); - Optional Redirects[] = {InputPath.str(), OutputPath.str(), {""}}; + std::optional Redirects[] = { + InputPath.str(), OutputPath.str(), {""}}; std::string ErrMsg; - int RC = sys::ExecuteAndWait(ViewOpts.DemanglerOpts[0], ArgsV, - /*env=*/None, Redirects, /*secondsToWait=*/0, - /*memoryLimit=*/0, &ErrMsg); + int RC = + sys::ExecuteAndWait(ViewOpts.DemanglerOpts[0], ArgsV, + /*env=*/std::nullopt, Redirects, /*secondsToWait=*/0, + /*memoryLimit=*/0, &ErrMsg); if (RC) { error(ErrMsg, ViewOpts.DemanglerOpts[0]); return; @@ -671,13 +675,6 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { "file"), cl::cat(FilteringCategory)); - // Allow for accepting previous option name. - cl::list NameFilterFilesDeprecated( - "name-whitelist", cl::Optional, cl::Hidden, - cl::desc("Show code coverage only for functions listed in the given " - "file. Deprecated, use -name-allowlist instead"), - cl::cat(FilteringCategory)); - cl::list NameRegexFilters( "name-regex", cl::Optional, cl::desc("Show code coverage only for functions that match the given " @@ -815,16 +812,10 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { } // Read in -name-allowlist files. - if (!NameFilterFiles.empty() || !NameFilterFilesDeprecated.empty()) { + if (!NameFilterFiles.empty()) { std::string SpecialCaseListErr; - if (!NameFilterFiles.empty()) - NameAllowlist = SpecialCaseList::create( - NameFilterFiles, *vfs::getRealFileSystem(), SpecialCaseListErr); - if (!NameFilterFilesDeprecated.empty()) - NameAllowlist = SpecialCaseList::create(NameFilterFilesDeprecated, - *vfs::getRealFileSystem(), - SpecialCaseListErr); - + NameAllowlist = SpecialCaseList::create( + NameFilterFiles, *vfs::getRealFileSystem(), SpecialCaseListErr); if (!NameAllowlist) error(SpecialCaseListErr); } @@ -834,14 +825,9 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { auto NameFilterer = std::make_unique(); for (const auto &Name : NameFilters) NameFilterer->push_back(std::make_unique(Name)); - if (NameAllowlist) { - if (!NameFilterFiles.empty()) - NameFilterer->push_back( - std::make_unique(*NameAllowlist)); - if (!NameFilterFilesDeprecated.empty()) - NameFilterer->push_back( - std::make_unique(*NameAllowlist)); - } + if (NameAllowlist && !NameFilterFiles.empty()) + NameFilterer->push_back( + std::make_unique(*NameAllowlist)); for (const auto &Regex : NameRegexFilters) NameFilterer->push_back( std::make_unique(Regex)); @@ -1090,7 +1076,7 @@ int CodeCoverageTool::doShow(int argc, const char **argv, FilenameFunctionMap; for (const auto &SourceFile : SourceFiles) for (const auto &Function : Coverage->getCoveredFunctions(SourceFile)) - if (Filters.matches(*Coverage.get(), Function)) + if (Filters.matches(*Coverage, Function)) FilenameFunctionMap[SourceFile].push_back(&Function); // Only print filter matching functions for each file. @@ -1179,7 +1165,7 @@ int CodeCoverageTool::doReport(int argc, const char **argv, if (!Coverage) return 1; - CoverageReport Report(ViewOpts, *Coverage.get()); + CoverageReport Report(ViewOpts, *Coverage); if (!ShowFunctionSummaries) { if (SourceFiles.empty()) Report.renderFileReports(llvm::outs(), IgnoreFilenameFilters); @@ -1210,12 +1196,17 @@ int CodeCoverageTool::doExport(int argc, const char **argv, cl::desc("Don't export per-function data"), cl::cat(ExportCategory)); + cl::opt SkipBranches("skip-branches", cl::Optional, + cl::desc("Don't export branch data (LCOV)"), + cl::cat(ExportCategory)); + auto Err = commandLineParser(argc, argv); if (Err) return Err; ViewOpts.SkipExpansions = SkipExpansions; ViewOpts.SkipFunctions = SkipFunctions; + ViewOpts.SkipBranches = SkipBranches; if (ViewOpts.Format != CoverageViewOptions::OutputFormat::Text && ViewOpts.Format != CoverageViewOptions::OutputFormat::Lcov) { @@ -1240,16 +1231,16 @@ int CodeCoverageTool::doExport(int argc, const char **argv, switch (ViewOpts.Format) { case CoverageViewOptions::OutputFormat::Text: - Exporter = std::make_unique(*Coverage.get(), - ViewOpts, outs()); + Exporter = + std::make_unique(*Coverage, ViewOpts, outs()); break; case CoverageViewOptions::OutputFormat::HTML: // Unreachable because we should have gracefully terminated with an error // above. llvm_unreachable("Export in HTML is not supported!"); case CoverageViewOptions::OutputFormat::Lcov: - Exporter = std::make_unique(*Coverage.get(), - ViewOpts, outs()); + Exporter = + std::make_unique(*Coverage, ViewOpts, outs()); break; } -- cgit v1.2.3