[llvm] r330524 - [tools] Use WithColor for printing errors.

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 23 10:25:39 PDT 2018


Tests?

On Sat, Apr 21, 2018 at 2:15 PM Jonas Devlieghere via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

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


More information about the llvm-commits mailing list