diff options
author | Fangrui Song <maskray@google.com> | 2019-10-14 12:51:47 +0000 |
---|---|---|
committer | Fangrui Song <maskray@google.com> | 2019-10-14 12:51:47 +0000 |
commit | 83e52f5e1150018329b8907bb014c77ac382d611 (patch) | |
tree | 4fb2bb18e1b9295968011e48c476099adea4bb20 /llvm/tools/llvm-size | |
parent | 8535bed79504ffe3ed7f2de8c158a17e79e54736 (diff) | |
download | bcm5719-llvm-83e52f5e1150018329b8907bb014c77ac382d611.tar.gz bcm5719-llvm-83e52f5e1150018329b8907bb014c77ac382d611.zip |
[llvm-size] Tidy up error messages (PR42970)
Clean up some formatting inconsistencies in the error messages and correctly exit with non-zero in all error cases.
Differential Revision: https://reviews.llvm.org/D68906
Patch by Alex Cameron
llvm-svn: 374771
Diffstat (limited to 'llvm/tools/llvm-size')
-rw-r--r-- | llvm/tools/llvm-size/llvm-size.cpp | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/llvm/tools/llvm-size/llvm-size.cpp b/llvm/tools/llvm-size/llvm-size.cpp index da56199fe3c..7c63bc291f1 100644 --- a/llvm/tools/llvm-size/llvm-size.cpp +++ b/llvm/tools/llvm-size/llvm-size.cpp @@ -24,6 +24,7 @@ #include "llvm/Support/Format.h" #include "llvm/Support/InitLLVM.h" #include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/WithColor.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> #include <string> @@ -106,11 +107,9 @@ static bool HadError = false; static std::string ToolName; -static bool error(Twine Message) { +static void error(const Twine &Message, StringRef File) { HadError = true; - errs() << ToolName << ": " << Message << ".\n"; - errs().flush(); - return true; + WithColor::error(errs(), ToolName) << "'" << File << "': " << Message << "\n"; } // This version of error() prints the archive name and member name, for example: @@ -119,7 +118,7 @@ static bool error(Twine Message) { static void error(llvm::Error E, StringRef FileName, const Archive::Child &C, StringRef ArchitectureName = StringRef()) { HadError = true; - errs() << ToolName << ": " << FileName; + WithColor::error(errs(), ToolName) << "'" << FileName << "'"; Expected<StringRef> NameOrErr = C.getName(); // TODO: if we have a error getting the name then it would be nice to print @@ -138,7 +137,7 @@ static void error(llvm::Error E, StringRef FileName, const Archive::Child &C, raw_string_ostream OS(Buf); logAllUnhandledErrors(std::move(E), OS); OS.flush(); - errs() << " " << Buf << "\n"; + errs() << ": " << Buf << "\n"; } // This version of error() prints the file name and which architecture slice it // is from, for example: "foo.o (for architecture i386)" after the ToolName @@ -147,7 +146,7 @@ static void error(llvm::Error E, StringRef FileName, const Archive::Child &C, static void error(llvm::Error E, StringRef FileName, StringRef ArchitectureName = StringRef()) { HadError = true; - errs() << ToolName << ": " << FileName; + WithColor::error(errs(), ToolName) << "'" << FileName << "'"; if (!ArchitectureName.empty()) errs() << " (for architecture " << ArchitectureName << ") "; @@ -156,7 +155,7 @@ static void error(llvm::Error E, StringRef FileName, raw_string_ostream OS(Buf); logAllUnhandledErrors(std::move(E), OS); OS.flush(); - errs() << " " << Buf << "\n"; + errs() << ": " << Buf << "\n"; } /// Get the length of the string that represents @p num in Radix including the @@ -529,7 +528,7 @@ static bool checkMachOAndArchFlags(ObjectFile *O, StringRef Filename) { if (none_of(ArchFlags, [&](const std::string &Name) { return Name == T.getArchName(); })) { - error(Filename + ": No architecture specified"); + error("no architecture specified", Filename); return false; } return true; @@ -658,15 +657,15 @@ static void printFileSectionSizes(StringRef file) { error(std::move(Err), UA->getFileName()); } else { consumeError(AOrErr.takeError()); - error("Mach-O universal file: " + file + " for architecture " + - StringRef(I->getArchFlagName()) + - " is not a Mach-O file or an archive file"); + error("mach-o universal file for architecture " + + StringRef(I->getArchFlagName()) + + " is not a mach-o file or an archive file", + file); } } } if (!ArchFound) { - errs() << ToolName << ": file: " << file - << " does not contain architecture" << ArchFlags[i] << ".\n"; + error("file does not contain architecture " + ArchFlags[i], file); return; } } @@ -740,9 +739,10 @@ static void printFileSectionSizes(StringRef file) { error(std::move(Err), UA->getFileName()); } else { consumeError(AOrErr.takeError()); - error("Mach-O universal file: " + file + " for architecture " + - StringRef(I->getArchFlagName()) + - " is not a Mach-O file or an archive file"); + error("mach-o universal file for architecture " + + StringRef(I->getArchFlagName()) + + " is not a mach-o file or an archive file", + file); } return; } @@ -816,9 +816,10 @@ static void printFileSectionSizes(StringRef file) { error(std::move(Err), UA->getFileName()); } else { consumeError(AOrErr.takeError()); - error("Mach-O universal file: " + file + " for architecture " + - StringRef(I->getArchFlagName()) + - " is not a Mach-O file or an archive file"); + error("mach-o universal file for architecture " + + StringRef(I->getArchFlagName()) + + " is not a mach-o file or an archive file", + file); } } } else if (ObjectFile *o = dyn_cast<ObjectFile>(&Bin)) { @@ -836,8 +837,7 @@ static void printFileSectionSizes(StringRef file) { outs() << "\n"; } } else { - errs() << ToolName << ": " << file << ": " - << "Unrecognized file type.\n"; + error("unsupported file type", file); } // System V adds an extra newline at the end of each file. if (OutputFormat == sysv) |