<div dir="ltr">Tests?</div><br><div class="gmail_quote"><div dir="ltr">On Sat, Apr 21, 2018 at 2:15 PM Jonas Devlieghere via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: jdevlieghere<br>
Date: Sat Apr 21 14:11:59 2018<br>
New Revision: 330524<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=330524&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=330524&view=rev</a><br>
Log:<br>
[tools] Use WithColor for printing errors.<br>
<br>
Use convenience helpers in WithColor to print errors, warnings and notes<br>
in a few more tools.<br>
<br>
Modified:<br>
    llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp<br>
    llvm/trunk/tools/llvm-dis/llvm-dis.cpp<br>
    llvm/trunk/tools/llvm-opt-report/OptReport.cpp<br>
    llvm/trunk/tools/yaml2obj/yaml2elf.cpp<br>
<br>
Modified: llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp?rev=330524&r1=330523&r2=330524&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp?rev=330524&r1=330523&r2=330524&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp (original)<br>
+++ llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp Sat Apr 21 14:11:59 2018<br>
@@ -37,6 +37,7 @@<br>
 #include "llvm/Support/ManagedStatic.h"<br>
 #include "llvm/Support/MemoryBuffer.h"<br>
 #include "llvm/Support/SHA1.h"<br>
+#include "llvm/Support/WithColor.h"<br>
 #include "llvm/Support/raw_ostream.h"<br>
 using namespace llvm;<br>
<br>
@@ -444,7 +445,7 @@ static std::map<unsigned, PerBlockIDStat<br>
 /// ReportError - All bitcode analysis errors go through this function, making this a<br>
 /// good place to breakpoint if debugging.<br>
 static bool ReportError(const Twine &Err) {<br>
-  errs() << Err << "\n";<br>
+  WithColor::error() << Err << "\n";<br>
   return true;<br>
 }<br>
<br>
<br>
Modified: llvm/trunk/tools/llvm-dis/llvm-dis.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dis/llvm-dis.cpp?rev=330524&r1=330523&r2=330524&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dis/llvm-dis.cpp?rev=330524&r1=330523&r2=330524&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-dis/llvm-dis.cpp (original)<br>
+++ llvm/trunk/tools/llvm-dis/llvm-dis.cpp Sat Apr 21 14:11:59 2018<br>
@@ -32,6 +32,7 @@<br>
 #include "llvm/Support/InitLLVM.h"<br>
 #include "llvm/Support/MemoryBuffer.h"<br>
 #include "llvm/Support/ToolOutputFile.h"<br>
+#include "llvm/Support/WithColor.h"<br>
 #include <system_error><br>
 using namespace llvm;<br>
<br>
@@ -127,10 +128,10 @@ struct LLVMDisDiagnosticHandler : public<br>
     raw_ostream &OS = errs();<br>
     OS << Prefix << ": ";<br>
     switch (DI.getSeverity()) {<br>
-      case DS_Error: OS << "error: "; break;<br>
-      case DS_Warning: OS << "warning: "; break;<br>
+      case DS_Error: WithColor::error(OS); break;<br>
+      case DS_Warning: WithColor::warning(OS); break;<br>
       case DS_Remark: OS << "remark: "; break;<br>
-      case DS_Note: OS << "note: "; break;<br>
+      case DS_Note: WithColor::note(OS); break;<br>
     }<br>
<br>
     DiagnosticPrinterRawOStream DP(OS);<br>
<br>
Modified: llvm/trunk/tools/llvm-opt-report/OptReport.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-opt-report/OptReport.cpp?rev=330524&r1=330523&r2=330524&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-opt-report/OptReport.cpp?rev=330524&r1=330523&r2=330524&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-opt-report/OptReport.cpp (original)<br>
+++ llvm/trunk/tools/llvm-opt-report/OptReport.cpp Sat Apr 21 14:11:59 2018<br>
@@ -25,6 +25,7 @@<br>
 #include "llvm/Support/MemoryBuffer.h"<br>
 #include "llvm/Support/Path.h"<br>
 #include "llvm/Support/Program.h"<br>
+#include "llvm/Support/WithColor.h"<br>
 #include "llvm/Support/YAMLTraits.h"<br>
 #include "llvm/Support/raw_ostream.h"<br>
 #include <cstdlib><br>
@@ -273,8 +274,8 @@ static bool readLocationInfo(LocationInf<br>
   ErrorOr<std::unique_ptr<MemoryBuffer>> Buf =<br>
       MemoryBuffer::getFileOrSTDIN(InputFileName);<br>
   if (std::error_code EC = Buf.getError()) {<br>
-    errs() << "error: Can't open file " << InputFileName << ": " <<<br>
-              EC.message() << "\n";<br>
+    WithColor::error() << "Can't open file " << InputFileName << ": "<br>
+                       << EC.message() << "\n";<br>
     return false;<br>
   }<br>
<br>
@@ -282,7 +283,7 @@ static bool readLocationInfo(LocationInf<br>
   yaml::Stream Stream(Buf.get()->getBuffer(), SM);<br>
   collectLocationInfo(Stream, LocationInfo);<br>
<br>
-  return true; <br>
+  return true;<br>
 }<br>
<br>
 static bool writeReport(LocationInfoTy &LocationInfo) {<br>
@@ -290,8 +291,8 @@ static bool writeReport(LocationInfoTy &<br>
   llvm::raw_fd_ostream OS(OutputFileName, EC,<br>
               llvm::sys::fs::F_Text);<br>
   if (EC) {<br>
-    errs() << "error: Can't open file " << OutputFileName << ": " <<<br>
-              EC.message() << "\n";<br>
+    WithColor::error() << "Can't open file " << OutputFileName << ": "<br>
+                       << EC.message() << "\n";<br>
     return false;<br>
   }<br>
<br>
@@ -300,8 +301,8 @@ static bool writeReport(LocationInfoTy &<br>
     SmallString<128> FileName(FI.first);<br>
     if (!InputRelDir.empty()) {<br>
       if (std::error_code EC = sys::fs::make_absolute(InputRelDir, FileName)) {<br>
-        errs() << "error: Can't resolve file path to " << FileName << ": " <<<br>
-                  EC.message() << "\n";<br>
+        WithColor::error() << "Can't resolve file path to " << FileName << ": "<br>
+                           << EC.message() << "\n";<br>
         return false;<br>
       }<br>
     }<br>
@@ -311,8 +312,8 @@ static bool writeReport(LocationInfoTy &<br>
     ErrorOr<std::unique_ptr<MemoryBuffer>> Buf =<br>
         MemoryBuffer::getFile(FileName);<br>
     if (std::error_code EC = Buf.getError()) {<br>
-      errs() << "error: Can't open file " << FileName << ": " <<<br>
-                EC.message() << "\n";<br>
+      WithColor::error() << "Can't open file " << FileName << ": "<br>
+                         << EC.message() << "\n";<br>
       return false;<br>
     }<br>
<br>
@@ -396,7 +397,7 @@ static bool writeReport(LocationInfoTy &<br>
<br>
             if (!Printed)<br>
               OS << FuncName;<br>
-          } <br>
+          }<br>
<br>
           OS << ":\n";<br>
         }<br>
@@ -522,8 +523,7 @@ int main(int argc, const char **argv) {<br>
   if (!readLocationInfo(LocationInfo))<br>
     return 1;<br>
   if (!writeReport(LocationInfo))<br>
-    return 1; <br>
+    return 1;<br>
<br>
   return 0;<br>
 }<br>
-<br>
<br>
Modified: llvm/trunk/tools/yaml2obj/yaml2elf.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2elf.cpp?rev=330524&r1=330523&r2=330524&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2elf.cpp?rev=330524&r1=330523&r2=330524&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/yaml2obj/yaml2elf.cpp (original)<br>
+++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp Sat Apr 21 14:11:59 2018<br>
@@ -19,6 +19,7 @@<br>
 #include "llvm/Object/ELFObjectFile.h"<br>
 #include "llvm/ObjectYAML/ELFYAML.h"<br>
 #include "llvm/Support/MemoryBuffer.h"<br>
+#include "llvm/Support/WithColor.h"<br>
 #include "llvm/Support/YAMLTraits.h"<br>
 #include "llvm/Support/raw_ostream.h"<br>
<br>
@@ -243,8 +244,8 @@ bool ELFState<ELFT>::initSectionHeaders(<br>
     if (!Sec->Link.empty()) {<br>
       unsigned Index;<br>
       if (SN2I.lookup(Sec->Link, Index)) {<br>
-        errs() << "error: Unknown section referenced: '" << Sec->Link<br>
-               << "' at YAML section '" << Sec->Name << "'.\n";<br>
+        WithColor::error() << "Unknown section referenced: '" << Sec->Link<br>
+                           << "' at YAML section '" << Sec->Name << "'.\n";<br>
         return false;<br>
       }<br>
       SHeader.sh_link = Index;<br>
@@ -260,8 +261,8 @@ bool ELFState<ELFT>::initSectionHeaders(<br>
       unsigned Index;<br>
       if (SN2I.lookup(S->Info, Index)) {<br>
         if (S->Info.getAsInteger(0, Index)) {<br>
-          errs() << "error: Unknown section referenced: '" << S->Info<br>
-                 << "' at YAML section '" << S->Name << "'.\n";<br>
+          WithColor::error() << "Unknown section referenced: '" << S->Info<br>
+                             << "' at YAML section '" << S->Name << "'.\n";<br>
           return false;<br>
         }<br>
       }<br>
@@ -272,8 +273,8 @@ bool ELFState<ELFT>::initSectionHeaders(<br>
     } else if (auto S = dyn_cast<ELFYAML::Group>(Sec.get())) {<br>
       unsigned SymIdx;<br>
       if (SymN2I.lookup(S->Info, SymIdx)) {<br>
-        errs() << "error: Unknown symbol referenced: '" << S->Info<br>
-               << "' at YAML section '" << S->Name << "'.\n";<br>
+        WithColor::error() << "Unknown symbol referenced: '" << S->Info<br>
+                           << "' at YAML section '" << S->Name << "'.\n";<br>
         return false;<br>
       }<br>
       SHeader.sh_info = SymIdx;<br>
@@ -430,8 +431,8 @@ void ELFState<ELFT>::addSymbols(const st<br>
     if (!Sym.Section.empty()) {<br>
       unsigned Index;<br>
       if (SN2I.lookup(Sym.Section, Index)) {<br>
-        errs() << "error: Unknown section referenced: '" << Sym.Section<br>
-               << "' by YAML symbol " << Sym.Name << ".\n";<br>
+        WithColor::error() << "Unknown section referenced: '" << Sym.Section<br>
+                           << "' by YAML symbol " << Sym.Name << ".\n";<br>
         exit(1);<br>
       }<br>
       Symbol.st_shndx = Index;<br>
@@ -528,9 +529,9 @@ bool ELFState<ELFT>::writeSectionContent<br>
     if (member.sectionNameOrType == "GRP_COMDAT")<br>
       sectionIndex = llvm::ELF::GRP_COMDAT;<br>
     else if (SN2I.lookup(member.sectionNameOrType, sectionIndex)) {<br>
-      errs() << "error: Unknown section referenced: '"<br>
-             << member.sectionNameOrType << "' at YAML section' "<br>
-             << Section.Name << "\n";<br>
+      WithColor::error() << "Unknown section referenced: '"<br>
+                         << member.sectionNameOrType << "' at YAML section' "<br>
+                         << Section.Name << "\n";<br>
       return false;<br>
     }<br>
     SIdx = sectionIndex;<br>
@@ -574,8 +575,8 @@ template <class ELFT> bool ELFState<ELFT<br>
     DotShStrtab.add(Name);<br>
     // "+ 1" to take into account the SHT_NULL entry.<br>
     if (SN2I.addName(Name, i + 1)) {<br>
-      errs() << "error: Repeated section name: '" << Name<br>
-             << "' at YAML section number " << i << ".\n";<br>
+      WithColor::error() << "Repeated section name: '" << Name<br>
+                         << "' at YAML section number " << i << ".\n";<br>
       return false;<br>
     }<br>
   }<br>
@@ -602,7 +603,7 @@ ELFState<ELFT>::buildSymbolIndex(std::si<br>
     if (Sym.Name.empty())<br>
       continue;<br>
     if (SymN2I.addName(Sym.Name, StartIndex)) {<br>
-      errs() << "error: Repeated symbol name: '" << Sym.Name << "'.\n";<br>
+      WithColor::error() << "Repeated symbol name: '" << Sym.Name << "'.\n";<br>
       return false;<br>
     }<br>
   }<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>