diff options
Diffstat (limited to 'llvm/tools/llvm-cov/CodeCoverage.cpp')
| -rw-r--r-- | llvm/tools/llvm-cov/CodeCoverage.cpp | 78 |
1 files changed, 28 insertions, 50 deletions
diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp index 6c66858..1f2484c 100644 --- a/llvm/tools/llvm-cov/CodeCoverage.cpp +++ b/llvm/tools/llvm-cov/CodeCoverage.cpp @@ -153,7 +153,7 @@ private: bool HadSourceFiles = false; /// The path to the indexed profile. - std::optional<std::string> PGOFilename; + std::string PGOFilename; /// A list of input source files. std::vector<std::string> SourceFiles; @@ -455,12 +455,10 @@ static bool modifiedTimeGT(StringRef LHS, StringRef RHS) { } std::unique_ptr<CoverageMapping> CodeCoverageTool::load() { - if (PGOFilename) { - for (StringRef ObjectFilename : ObjectFilenames) - if (modifiedTimeGT(ObjectFilename, PGOFilename.value())) - warning("profile data may be out of date - object is newer", - ObjectFilename); - } + for (StringRef ObjectFilename : ObjectFilenames) + if (modifiedTimeGT(ObjectFilename, PGOFilename)) + warning("profile data may be out of date - object is newer", + ObjectFilename); auto FS = vfs::getRealFileSystem(); auto CoverageOrErr = CoverageMapping::load( ObjectFilenames, PGOFilename, *FS, CoverageArches, @@ -670,16 +668,11 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { "dump-collected-paths", cl::Optional, cl::Hidden, cl::desc("Show the collected paths to source files")); - cl::opt<std::string> PGOFilename( - "instr-profile", cl::Optional, + cl::opt<std::string, true> PGOFilename( + "instr-profile", cl::Required, cl::location(this->PGOFilename), cl::desc( "File with the profile data obtained after an instrumented run")); - cl::opt<bool> EmptyProfile( - "empty-profile", cl::Optional, - cl::desc("Use a synthetic profile with no data to generate " - "baseline coverage")); - cl::list<std::string> Arches( "arch", cl::desc("architectures of the coverage mapping binaries")); @@ -812,15 +805,6 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { } this->CheckBinaryIDs = CheckBinaryIDs; - if (!PGOFilename.empty() == EmptyProfile) { - error( - "exactly one of -instr-profile and -empty-profile must be specified"); - return 1; - } - if (!PGOFilename.empty()) { - this->PGOFilename = std::make_optional(PGOFilename.getValue()); - } - if (!CovFilename.empty()) ObjectFilenames.emplace_back(CovFilename); for (const std::string &Filename : CovFilenames) @@ -1132,22 +1116,20 @@ int CodeCoverageTool::doShow(int argc, const char **argv, } } - if (PGOFilename) { - sys::fs::file_status Status; - if (std::error_code EC = sys::fs::status(PGOFilename.value(), Status)) { - error("could not read profile data!" + EC.message(), PGOFilename.value()); - return 1; - } + sys::fs::file_status Status; + if (std::error_code EC = sys::fs::status(PGOFilename, Status)) { + error("could not read profile data!" + EC.message(), PGOFilename); + return 1; + } - if (ShowCreatedTime) { - auto ModifiedTime = Status.getLastModificationTime(); - std::string ModifiedTimeStr = to_string(ModifiedTime); - size_t found = ModifiedTimeStr.rfind(':'); - ViewOpts.CreatedTimeStr = - (found != std::string::npos) - ? "Created: " + ModifiedTimeStr.substr(0, found) - : "Created: " + ModifiedTimeStr; - } + if (ShowCreatedTime) { + auto ModifiedTime = Status.getLastModificationTime(); + std::string ModifiedTimeStr = to_string(ModifiedTime); + size_t found = ModifiedTimeStr.rfind(':'); + ViewOpts.CreatedTimeStr = + (found != std::string::npos) + ? "Created: " + ModifiedTimeStr.substr(0, found) + : "Created: " + ModifiedTimeStr; } auto Coverage = load(); @@ -1256,12 +1238,10 @@ int CodeCoverageTool::doReport(int argc, const char **argv, return 1; } - if (PGOFilename) { - sys::fs::file_status Status; - if (std::error_code EC = sys::fs::status(PGOFilename.value(), Status)) { - error("could not read profile data!" + EC.message(), PGOFilename.value()); - return 1; - } + sys::fs::file_status Status; + if (std::error_code EC = sys::fs::status(PGOFilename, Status)) { + error("could not read profile data!" + EC.message(), PGOFilename); + return 1; } auto Coverage = load(); @@ -1323,12 +1303,10 @@ int CodeCoverageTool::doExport(int argc, const char **argv, return 1; } - if (PGOFilename) { - sys::fs::file_status Status; - if (std::error_code EC = sys::fs::status(PGOFilename.value(), Status)) { - error("could not read profile data!" + EC.message(), PGOFilename.value()); - return 1; - } + sys::fs::file_status Status; + if (std::error_code EC = sys::fs::status(PGOFilename, Status)) { + error("could not read profile data!" + EC.message(), PGOFilename); + return 1; } auto Coverage = load(); |
