[PATCH] D45658: [llvm-profdata] Use WithColor for printing errors

Jonas Devlieghere via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 14 15:20:50 PDT 2018


JDevlieghere created this revision.
JDevlieghere added reviewers: vsk, bogner.

Use convenience helpers in WithColor to print errors and warnings.


Repository:
  rL LLVM

https://reviews.llvm.org/D45658

Files:
  llvm/tools/llvm-profdata/llvm-profdata.cpp


Index: llvm/tools/llvm-profdata/llvm-profdata.cpp
===================================================================
--- llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -27,27 +27,33 @@
 #include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/WithColor.h"
 #include "llvm/Support/ThreadPool.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 
 using namespace llvm;
 
 enum ProfileFormat { PF_None = 0, PF_Text, PF_Binary, PF_GCC };
 
-static void warn(StringRef Prefix, Twine Message, std::string Whence = "",
+static void warn(Twine Message, std::string Whence = "",
                  std::string Hint = "") {
-  errs() << Prefix;
+  WithColor::warning();
   if (!Whence.empty())
     errs() << Whence << ": ";
   errs() << Message << "\n";
   if (!Hint.empty())
-    errs() << Hint << "\n";
+    WithColor::note() << Hint << "\n";
 }
 
 static void exitWithError(Twine Message, std::string Whence = "",
                           std::string Hint = "") {
-  warn("error: ", Message, Whence, Hint);
+  WithColor::error();
+  if (!Whence.empty())
+    errs() << Whence << ": ";
+  errs() << Message << "\n";
+  if (!Hint.empty())
+    WithColor::note() << Hint << "\n";
   ::exit(1);
 }
 
@@ -296,7 +302,7 @@
     if (isFatalError(IPE))
       exitWithError(make_error<InstrProfError>(IPE), WC->ErrWhence);
     else
-      warn("warning: ", toString(make_error<InstrProfError>(IPE)),
+      warn(toString(make_error<InstrProfError>(IPE)),
            WC->ErrWhence);
   }
 
@@ -785,7 +791,7 @@
     exitWithErrorCode(EC, OutputFilename);
 
   if (ShowAllFunctions && !ShowFunction.empty())
-    errs() << "warning: -function argument ignored: showing all functions\n";
+    WithColor::warning() << "-function argument ignored: showing all functions\n";
 
   std::vector<uint32_t> Cutoffs(DetailedSummaryCutoffs.begin(),
                                 DetailedSummaryCutoffs.end());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45658.142528.patch
Type: text/x-patch
Size: 2021 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180414/087011b2/attachment.bin>


More information about the llvm-commits mailing list