Skip to content

Commit

Permalink
[Support] Make error banner optional in logAllUnhandledErrors
Browse files Browse the repository at this point in the history
In a lot of places an empty string was passed as the ErrorBanner to
logAllUnhandledErrors. This patch makes that argument optional to
simplify the call sites.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346604 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
JDevlieghere committed Nov 11, 2018
1 parent 3283290 commit 686dfe3
Show file tree
Hide file tree
Showing 25 changed files with 61 additions and 61 deletions.
6 changes: 5 additions & 1 deletion include/llvm/Support/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -953,10 +953,14 @@ Expected<T> handleExpected(Expected<T> ValOrErr, RecoveryFtor &&RecoveryPath,
/// will be printed before the first one is logged. A newline will be printed
/// after each error.
///
/// This function is compatible with the helpers from Support/WithColor.h. You
/// can pass any of them as the OS. Please consider using them instead of
/// including 'error: ' in the ErrorBanner.
///
/// This is useful in the base level of your program to allow clean termination
/// (allowing clean deallocation of resources, etc.), while reporting error
/// information to the user.
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner);
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner = {});

/// Write all error messages (if any) in E to a string. The newline character
/// is used to separate error messages.
Expand Down
2 changes: 1 addition & 1 deletion lib/ExecutionEngine/MCJIT/MCJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void MCJIT::generateCodeForModule(Module *M) {
if (!LoadedObject) {
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(LoadedObject.takeError(), OS, "");
logAllUnhandledErrors(LoadedObject.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ RuntimeDyldCOFF::loadObject(const object::ObjectFile &O) {
} else {
HasError = true;
raw_string_ostream ErrStream(ErrorStr);
logAllUnhandledErrors(ObjSectionToIDOrErr.takeError(), ErrStream, "");
logAllUnhandledErrors(ObjSectionToIDOrErr.takeError(), ErrStream);
return nullptr;
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ RuntimeDyldELF::loadObject(const object::ObjectFile &O) {
else {
HasError = true;
raw_string_ostream ErrStream(ErrorStr);
logAllUnhandledErrors(ObjSectionToIDOrErr.takeError(), ErrStream, "");
logAllUnhandledErrors(ObjSectionToIDOrErr.takeError(), ErrStream);
return nullptr;
}
}
Expand Down Expand Up @@ -1130,7 +1130,7 @@ RuntimeDyldELF::processRelocationRef(
if (!SymTypeOrErr) {
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(SymTypeOrErr.takeError(), OS, "");
logAllUnhandledErrors(SymTypeOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
Expand All @@ -1151,7 +1151,7 @@ RuntimeDyldELF::processRelocationRef(
if (!SectionOrErr) {
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(SectionOrErr.takeError(), OS, "");
logAllUnhandledErrors(SectionOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ RuntimeDyldMachO::loadObject(const object::ObjectFile &O) {
else {
HasError = true;
raw_string_ostream ErrStream(ErrorStr);
logAllUnhandledErrors(ObjSectionToIDOrErr.takeError(), ErrStream, "");
logAllUnhandledErrors(ObjSectionToIDOrErr.takeError(), ErrStream);
return nullptr;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static bool isThumbFunc(symbol_iterator Symbol, const ObjectFile &Obj,
if (!SymTypeOrErr) {
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(SymTypeOrErr.takeError(), OS, "");
logAllUnhandledErrors(SymTypeOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/LTO/LTOModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool LTOModule::isBitcodeFile(StringRef Path) {
bool LTOModule::isThinLTO() {
Expected<BitcodeLTOInfo> Result = getBitcodeLTOInfo(MBRef);
if (!Result) {
logAllUnhandledErrors(Result.takeError(), errs(), "");
logAllUnhandledErrors(Result.takeError(), errs());
return false;
}
return Result->IsThinLTO;
Expand Down
6 changes: 3 additions & 3 deletions lib/Object/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect,
if (!SecOrErr) {
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(SecOrErr.takeError(), OS, "");
logAllUnhandledErrors(SecOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
Expand Down Expand Up @@ -187,7 +187,7 @@ const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI) {
if (!Ret) {
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(Ret.takeError(), OS, "");
logAllUnhandledErrors(Ret.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
Expand All @@ -199,7 +199,7 @@ uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI) {
if (!Ret) {
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(Ret.takeError(), OS, "");
logAllUnhandledErrors(Ret.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Support/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void report_fatal_error(Error Err, bool GenCrashDiag) {
std::string ErrMsg;
{
raw_string_ostream ErrStream(ErrMsg);
logAllUnhandledErrors(std::move(Err), ErrStream, "");
logAllUnhandledErrors(std::move(Err), ErrStream);
}
report_fatal_error(ErrMsg);
}
Expand Down
2 changes: 1 addition & 1 deletion tools/lli/lli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ int main(int argc, char **argv, char * const *envp) {
if (!ArOrErr) {
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(ArOrErr.takeError(), OS, "");
logAllUnhandledErrors(ArOrErr.takeError(), OS);
OS.flush();
errs() << Buf;
exit(1);
Expand Down
2 changes: 1 addition & 1 deletion tools/llvm-cov/TestingSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int convertForTestingMain(int argc, const char *argv[]) {
if (!ObjErr) {
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(ObjErr.takeError(), OS, "");
logAllUnhandledErrors(ObjErr.takeError(), OS);
OS.flush();
errs() << "error: " << Buf;
return 1;
Expand Down
5 changes: 3 additions & 2 deletions tools/llvm-cxxdump/llvm-cxxdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ static void error(std::error_code EC) {
static void error(Error Err) {
if (!Err)
return;
logAllUnhandledErrors(std::move(Err), WithColor::error(outs(), ""), "reading file: ");
logAllUnhandledErrors(std::move(Err), WithColor::error(outs()),
"reading file: ");
outs().flush();
exit(1);
}
Expand Down Expand Up @@ -497,7 +498,7 @@ static void dumpArchive(const Archive *Arc) {
if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError())) {
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(std::move(E), OS, "");
logAllUnhandledErrors(std::move(E), OS);
OS.flush();
reportError(Arc->getFileName(), Buf);
}
Expand Down
13 changes: 6 additions & 7 deletions tools/llvm-nm/llvm-nm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ static bool error(std::error_code EC, Twine Path = Twine()) {

// This version of error() prints the archive name and member name, for example:
// "libx.a(foo.o)" after the ToolName before the error message. It sets
// HadError but returns allowing the code to move on to other archive members.
// HadError but returns allowing the code to move on to other archive members.
static void error(llvm::Error E, StringRef FileName, const Archive::Child &C,
StringRef ArchitectureName = StringRef()) {
HadError = true;
Expand All @@ -230,15 +230,15 @@ static void error(llvm::Error E, StringRef FileName, const Archive::Child &C,

std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(std::move(E), OS, "");
logAllUnhandledErrors(std::move(E), OS);
OS.flush();
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
// before the error message. It sets HadError but returns allowing the code to
// move on to other architecture slices.
// move on to other architecture slices.
static void error(llvm::Error E, StringRef FileName,
StringRef ArchitectureName = StringRef()) {
HadError = true;
Expand All @@ -249,7 +249,7 @@ static void error(llvm::Error E, StringRef FileName,

std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(std::move(E), OS, "");
logAllUnhandledErrors(std::move(E), OS);
OS.flush();
errs() << " " << Buf << "\n";
}
Expand Down Expand Up @@ -1029,8 +1029,7 @@ static char getSymbolNMTypeChar(MachOObjectFile &Obj, basic_symbol_iterator I) {
StringRef SectionName;
Obj.getSectionName(Ref, SectionName);
StringRef SegmentName = Obj.getSectionFinalSegmentName(Ref);
if (Obj.is64Bit() &&
Obj.getHeader64().filetype == MachO::MH_KEXT_BUNDLE &&
if (Obj.is64Bit() && Obj.getHeader64().filetype == MachO::MH_KEXT_BUNDLE &&
SegmentName == "__TEXT_EXEC" && SectionName == "__text")
return 't';
if (SegmentName == "__TEXT" && SectionName == "__text")
Expand Down Expand Up @@ -1606,7 +1605,7 @@ dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName,
uint64_t lc_main_offset = UINT64_MAX;
for (const auto &Command : MachO->load_commands()) {
if (Command.C.cmd == MachO::LC_FUNCTION_STARTS) {
// We found a function starts segment, parse the addresses for
// We found a function starts segment, parse the addresses for
// consumption.
MachO::linkedit_data_command LLC =
MachO->getLinkeditDataLoadCommand(Command);
Expand Down
2 changes: 1 addition & 1 deletion tools/llvm-objcopy/llvm-objcopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, Error E) {
assert(E);
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(std::move(E), OS, "");
logAllUnhandledErrors(std::move(E), OS);
OS.flush();
WithColor::error(errs(), ToolName) << "'" << File << "': " << Buf;
exit(1);
Expand Down
2 changes: 1 addition & 1 deletion tools/llvm-objcopy/llvm-objcopy.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ template <class T> T unwrapOrError(Expected<T> EO) {
return *EO;
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(EO.takeError(), OS, "");
logAllUnhandledErrors(EO.takeError(), OS);
OS.flush();
error(Buf);
}
Expand Down
4 changes: 2 additions & 2 deletions tools/llvm-objdump/llvm-objdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ LLVM_ATTRIBUTE_NORETURN void llvm::report_error(StringRef File,
assert(E);
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(std::move(E), OS, "");
logAllUnhandledErrors(std::move(E), OS);
OS.flush();
errs() << ToolName << ": '" << File << "': " << Buf;
exit(1);
Expand All @@ -392,7 +392,7 @@ LLVM_ATTRIBUTE_NORETURN void llvm::report_error(StringRef ArchiveName,
errs() << " (for architecture " << ArchitectureName << ")";
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(std::move(E), OS, "");
logAllUnhandledErrors(std::move(E), OS);
OS.flush();
errs() << ": " << Buf;
exit(1);
Expand Down
14 changes: 7 additions & 7 deletions tools/llvm-readobj/ARMWinEHPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ bool Decoder::dumpXDataRecord(const COFFObjectFile &COFF,
if (!Name) {
std::string Buf;
llvm::raw_string_ostream OS(Buf);
logAllUnhandledErrors(Name.takeError(), OS, "");
logAllUnhandledErrors(Name.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
Expand Down Expand Up @@ -942,7 +942,7 @@ bool Decoder::dumpUnpackedEntry(const COFFObjectFile &COFF,
if (!FunctionNameOrErr) {
std::string Buf;
llvm::raw_string_ostream OS(Buf);
logAllUnhandledErrors(FunctionNameOrErr.takeError(), OS, "");
logAllUnhandledErrors(FunctionNameOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
Expand All @@ -951,7 +951,7 @@ bool Decoder::dumpUnpackedEntry(const COFFObjectFile &COFF,
if (!FunctionAddressOrErr) {
std::string Buf;
llvm::raw_string_ostream OS(Buf);
logAllUnhandledErrors(FunctionAddressOrErr.takeError(), OS, "");
logAllUnhandledErrors(FunctionAddressOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
Expand All @@ -967,7 +967,7 @@ bool Decoder::dumpUnpackedEntry(const COFFObjectFile &COFF,
if (!Name) {
std::string Buf;
llvm::raw_string_ostream OS(Buf);
logAllUnhandledErrors(Name.takeError(), OS, "");
logAllUnhandledErrors(Name.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
Expand All @@ -976,7 +976,7 @@ bool Decoder::dumpUnpackedEntry(const COFFObjectFile &COFF,
if (!AddressOrErr) {
std::string Buf;
llvm::raw_string_ostream OS(Buf);
logAllUnhandledErrors(AddressOrErr.takeError(), OS, "");
logAllUnhandledErrors(AddressOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
Expand Down Expand Up @@ -1025,7 +1025,7 @@ bool Decoder::dumpPackedEntry(const object::COFFObjectFile &COFF,
if (!FunctionNameOrErr) {
std::string Buf;
llvm::raw_string_ostream OS(Buf);
logAllUnhandledErrors(FunctionNameOrErr.takeError(), OS, "");
logAllUnhandledErrors(FunctionNameOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
Expand All @@ -1034,7 +1034,7 @@ bool Decoder::dumpPackedEntry(const object::COFFObjectFile &COFF,
if (!FunctionAddressOrErr) {
std::string Buf;
llvm::raw_string_ostream OS(Buf);
logAllUnhandledErrors(FunctionAddressOrErr.takeError(), OS, "");
logAllUnhandledErrors(FunctionAddressOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
Expand Down
2 changes: 1 addition & 1 deletion tools/llvm-readobj/llvm-readobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace llvm {
return *EO;
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(EO.takeError(), OS, "");
logAllUnhandledErrors(EO.takeError(), OS);
OS.flush();
reportError(Buf);
}
Expand Down
6 changes: 3 additions & 3 deletions tools/llvm-rtdyld/llvm-rtdyld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ static int printLineInfoForInput(bool LoadObjects, bool UseDebugObj) {
if (!MaybeObj) {
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(MaybeObj.takeError(), OS, "");
logAllUnhandledErrors(MaybeObj.takeError(), OS);
OS.flush();
ErrorAndExit("unable to create object file: '" + Buf + "'");
}
Expand Down Expand Up @@ -438,7 +438,7 @@ static int executeInput() {
if (!MaybeObj) {
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(MaybeObj.takeError(), OS, "");
logAllUnhandledErrors(MaybeObj.takeError(), OS);
OS.flush();
ErrorAndExit("unable to create object file: '" + Buf + "'");
}
Expand Down Expand Up @@ -710,7 +710,7 @@ static int linkAndVerify() {
if (!MaybeObj) {
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(MaybeObj.takeError(), OS, "");
logAllUnhandledErrors(MaybeObj.takeError(), OS);
OS.flush();
ErrorAndExit("unable to create object file: '" + Buf + "'");
}
Expand Down
4 changes: 2 additions & 2 deletions tools/llvm-size/llvm-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static void error(llvm::Error E, StringRef FileName, const Archive::Child &C,

std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(std::move(E), OS, "");
logAllUnhandledErrors(std::move(E), OS);
OS.flush();
errs() << " " << Buf << "\n";
}
Expand All @@ -158,7 +158,7 @@ static void error(llvm::Error E, StringRef FileName,

std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(std::move(E), OS, "");
logAllUnhandledErrors(std::move(E), OS);
OS.flush();
errs() << " " << Buf << "\n";
}
Expand Down
2 changes: 1 addition & 1 deletion tools/llvm-xray/xray-stacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ static CommandRegistration Unused(&Stack, []() -> Error {
Twine("Failed loading input file '") + Filename + "'",
std::make_error_code(std::errc::invalid_argument)),
TraceOrErr.takeError());
logAllUnhandledErrors(TraceOrErr.takeError(), errs(), "");
logAllUnhandledErrors(TraceOrErr.takeError(), errs());
continue;
}
auto &T = *TraceOrErr;
Expand Down
2 changes: 1 addition & 1 deletion tools/obj2yaml/coff2yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void COFFDumper::dumpSections(unsigned NumSections) {
if (!SymbolNameOrErr) {
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(SymbolNameOrErr.takeError(), OS, "");
logAllUnhandledErrors(SymbolNameOrErr.takeError(), OS);
OS.flush();
report_fatal_error(Buf);
}
Expand Down
2 changes: 1 addition & 1 deletion tools/obj2yaml/obj2yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static void reportError(StringRef Input, Error Err) {
Input = "<stdin>";
std::string ErrMsg;
raw_string_ostream OS(ErrMsg);
logAllUnhandledErrors(std::move(Err), OS, "");
logAllUnhandledErrors(std::move(Err), OS);
OS.flush();
errs() << "Error reading file: " << Input << ": " << ErrMsg;
errs().flush();
Expand Down
Loading

0 comments on commit 686dfe3

Please sign in to comment.