[Hexagon] Alphabetical ordering of functions, NFC.
[oota-llvm.git] / tools / llvm-cov / CodeCoverage.cpp
index c9bb7cefa064ef822736a05f26b104391aa23f9f..4ff53301881d1b55069d71a99ceb1abccf4d2b9c 100644 (file)
@@ -116,8 +116,7 @@ CodeCoverageTool::getSourceFile(StringRef SourceFile) {
     error(EC.message(), SourceFile);
     return EC;
   }
-  LoadedSourceFiles.push_back(
-      std::make_pair(SourceFile, std::move(Buffer.get())));
+  LoadedSourceFiles.emplace_back(SourceFile, std::move(Buffer.get()));
   return *LoadedSourceFiles.back().second;
 }
 
@@ -195,7 +194,20 @@ CodeCoverageTool::createSourceFileView(StringRef SourceFile,
   return View;
 }
 
+static bool modifiedTimeGT(StringRef LHS, StringRef RHS) {
+  sys::fs::file_status Status;
+  if (sys::fs::status(LHS, Status))
+    return false;
+  auto LHSTime = Status.getLastModificationTime();
+  if (sys::fs::status(RHS, Status))
+    return false;
+  auto RHSTime = Status.getLastModificationTime();
+  return LHSTime > RHSTime;
+}
+
 std::unique_ptr<CoverageMapping> CodeCoverageTool::load() {
+  if (modifiedTimeGT(ObjectFilename, PGOFilename))
+    errs() << "warning: profile data may be out of date - object is newer\n";
   auto CoverageOrErr = CoverageMapping::load(ObjectFilename, PGOFilename,
                                              CoverageArch);
   if (std::error_code EC = CoverageOrErr.getError()) {
@@ -294,23 +306,18 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
                "greater than the given threshold"),
       cl::cat(FilteringCategory));
 
-  enum Colors { Auto, Always, Never };
-  cl::opt<Colors> Color(
-      "color", cl::desc("Configure color output:"), cl::init(Colors::Auto),
-      cl::values(clEnumValN(Colors::Auto, "auto",
-                            "Enable color if stdout seems to support it"),
-                 clEnumValN(Colors::Always, "always", "Enable color"),
-                 clEnumValN(Colors::Never, "never", "Disable color"),
-                 clEnumValEnd));
+  cl::opt<cl::boolOrDefault> UseColor(
+      "use-color", cl::desc("Emit colored output (default=autodetect)"),
+      cl::init(cl::BOU_UNSET));
 
   auto commandLineParser = [&, this](int argc, const char **argv) -> int {
     cl::ParseCommandLineOptions(argc, argv, "LLVM code coverage tool\n");
     ViewOpts.Debug = DebugDump;
     CompareFilenamesOnly = FilenameEquivalence;
 
-    ViewOpts.Colors =
-        Color == Colors::Always ||
-        (Color == Colors::Auto && sys::Process::StandardOutHasColors());
+    ViewOpts.Colors = UseColor == cl::BOU_UNSET
+                          ? sys::Process::StandardOutHasColors()
+                          : UseColor == cl::BOU_TRUE;
 
     // Create the function filters
     if (!NameFilters.empty() || !NameRegexFilters.empty()) {