[llvm] r330262 - [llvm-profdata] Use WithColor for printing errors

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 18 07:42:33 PDT 2018


Author: jdevlieghere
Date: Wed Apr 18 07:42:33 2018
New Revision: 330262

URL: http://llvm.org/viewvc/llvm-project?rev=330262&view=rev
Log:
[llvm-profdata] Use WithColor for printing errors

Use convenience helpers in WithColor to print errors and warnings.

Differential revision: https://reviews.llvm.org/D45658

Modified:
    llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp

Modified: llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp?rev=330262&r1=330261&r2=330262&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp (original)
+++ llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp Wed Apr 18 07:42:33 2018
@@ -27,6 +27,7 @@
 #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>
@@ -35,19 +36,24 @@ 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 @@ static void mergeInstrProfile(const Weig
     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 @@ static int show_main(int argc, const cha
     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());




More information about the llvm-commits mailing list