diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:04 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:11 +0000 |
commit | e3b557809604d036af6e00c60f012c2025b59a5e (patch) | |
tree | 8a11ba2269a3b669601e2fd41145b174008f4da8 /llvm/tools/llvm-cov/CodeCoverage.cpp | |
parent | 08e8dd7b9db7bb4a9de26d44c1cbfd24e869c014 (diff) |
Diffstat (limited to 'llvm/tools/llvm-cov/CodeCoverage.cpp')
-rw-r--r-- | llvm/tools/llvm-cov/CodeCoverage.cpp | 67 |
1 files changed, 29 insertions, 38 deletions
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 <functional> #include <map> +#include <optional> #include <system_error> using namespace llvm; @@ -84,7 +85,7 @@ private: bool isEquivalentFile(StringRef FilePath1, StringRef FilePath2); /// Retrieve a file status with a cache. - Optional<sys::fs::file_status> getFileStatus(StringRef FilePath); + std::optional<sys::fs::file_status> getFileStatus(StringRef FilePath); /// Return a memory buffer for the given source file. ErrorOr<const MemoryBuffer &> 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<std::pair<std::string, std::string>> PathRemapping; + std::optional<std::pair<std::string, std::string>> PathRemapping; /// File status cache used when finding the same file. - StringMap<Optional<sys::fs::file_status>> FileStatusCache; + StringMap<std::optional<sys::fs::file_status>> FileStatusCache; /// The architecture the coverage mapping data targets. std::vector<StringRef> CoverageArches; @@ -248,7 +249,7 @@ void CodeCoverageTool::collectPaths(const std::string &Path) { } } -Optional<sys::fs::file_status> +std::optional<sys::fs::file_status> 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<StringRef> ArgsV; + ArgsV.reserve(ViewOpts.DemanglerOpts.size()); for (StringRef Arg : ViewOpts.DemanglerOpts) ArgsV.push_back(Arg); - Optional<StringRef> Redirects[] = {InputPath.str(), OutputPath.str(), {""}}; + std::optional<StringRef> 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<std::string> 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<std::string> 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<CoverageFilters>(); for (const auto &Name : NameFilters) NameFilterer->push_back(std::make_unique<NameCoverageFilter>(Name)); - if (NameAllowlist) { - if (!NameFilterFiles.empty()) - NameFilterer->push_back( - std::make_unique<NameAllowlistCoverageFilter>(*NameAllowlist)); - if (!NameFilterFilesDeprecated.empty()) - NameFilterer->push_back( - std::make_unique<NameWhitelistCoverageFilter>(*NameAllowlist)); - } + if (NameAllowlist && !NameFilterFiles.empty()) + NameFilterer->push_back( + std::make_unique<NameAllowlistCoverageFilter>(*NameAllowlist)); for (const auto &Regex : NameRegexFilters) NameFilterer->push_back( std::make_unique<NameRegexCoverageFilter>(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<bool> 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<CoverageExporterJson>(*Coverage.get(), - ViewOpts, outs()); + Exporter = + std::make_unique<CoverageExporterJson>(*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<CoverageExporterLcov>(*Coverage.get(), - ViewOpts, outs()); + Exporter = + std::make_unique<CoverageExporterLcov>(*Coverage, ViewOpts, outs()); break; } |