forked from OSchip/llvm-project
[llvm] Update report_fatal_error calls from raw_string_ostream to use Twine(OS.str())
As described on D111049, we're trying to remove the <string> dependency from error handling and replace uses of report_fatal_error(const std::string&) with the Twine() variant which can be forward declared. We can use the raw_string_ostream::str() method to perform the implicit flush() and return a reference to the std::string container that we can then wrap inside Twine().
This commit is contained in:
parent
5bc32ad08d
commit
2e5daac217
|
@ -2517,7 +2517,7 @@ const MCExpr *AsmPrinter::lowerConstant(const Constant *CV) {
|
|||
OS << "Unsupported expression in static initializer: ";
|
||||
CE->printAsOperand(OS, /*PrintType=*/false,
|
||||
!MF ? nullptr : MF->getFunction().getParent());
|
||||
report_fatal_error(OS.str());
|
||||
report_fatal_error(Twine(OS.str()));
|
||||
}
|
||||
case Instruction::GetElementPtr: {
|
||||
// Generate a symbolic expression for the byte address
|
||||
|
|
|
@ -582,7 +582,7 @@ void AsmPrinter::PrintSpecial(const MachineInstr *MI, raw_ostream &OS,
|
|||
raw_string_ostream Msg(msg);
|
||||
Msg << "Unknown special formatter '" << Code
|
||||
<< "' for machine instr: " << *MI;
|
||||
report_fatal_error(Msg.str());
|
||||
report_fatal_error(Twine(Msg.str()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9938,12 +9938,9 @@ SDValue SelectionDAG::getSymbolFunctionGlobalAddress(SDValue Op,
|
|||
|
||||
std::string ErrorStr;
|
||||
raw_string_ostream ErrorFormatter(ErrorStr);
|
||||
|
||||
ErrorFormatter << "Undefined external symbol ";
|
||||
ErrorFormatter << '"' << Symbol << '"';
|
||||
ErrorFormatter.flush();
|
||||
|
||||
report_fatal_error(ErrorStr);
|
||||
report_fatal_error(Twine(ErrorFormatter.str()));
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
|
@ -218,8 +218,7 @@ void MCJIT::generateCodeForModule(Module *M) {
|
|||
std::string Buf;
|
||||
raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(LoadedObject.takeError(), OS);
|
||||
OS.flush();
|
||||
report_fatal_error(Buf);
|
||||
report_fatal_error(Twine(OS.str()));
|
||||
}
|
||||
std::unique_ptr<RuntimeDyld::LoadedObjectInfo> L =
|
||||
Dyld.loadObject(*LoadedObject.get());
|
||||
|
|
|
@ -1236,8 +1236,7 @@ RuntimeDyldELF::processRelocationRef(
|
|||
std::string Buf;
|
||||
raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(SymTypeOrErr.takeError(), OS);
|
||||
OS.flush();
|
||||
report_fatal_error(Buf);
|
||||
report_fatal_error(Twine(OS.str()));
|
||||
}
|
||||
SymType = *SymTypeOrErr;
|
||||
}
|
||||
|
@ -1257,8 +1256,7 @@ RuntimeDyldELF::processRelocationRef(
|
|||
std::string Buf;
|
||||
raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(SectionOrErr.takeError(), OS);
|
||||
OS.flush();
|
||||
report_fatal_error(Buf);
|
||||
report_fatal_error(Twine(OS.str()));
|
||||
}
|
||||
section_iterator si = *SectionOrErr;
|
||||
if (si == Obj.section_end())
|
||||
|
|
|
@ -29,8 +29,7 @@ static bool isThumbFunc(object::symbol_iterator Symbol,
|
|||
std::string Buf;
|
||||
raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(SymTypeOrErr.takeError(), OS);
|
||||
OS.flush();
|
||||
report_fatal_error(Buf);
|
||||
report_fatal_error(Twine(OS.str()));
|
||||
}
|
||||
|
||||
if (*SymTypeOrErr != object::SymbolRef::ST_Function)
|
||||
|
|
|
@ -222,8 +222,7 @@ void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect,
|
|||
std::string Buf;
|
||||
raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(SecOrErr.takeError(), OS);
|
||||
OS.flush();
|
||||
report_fatal_error(Buf);
|
||||
report_fatal_error(Twine(OS.str()));
|
||||
}
|
||||
*unwrap(Sect) = *SecOrErr;
|
||||
}
|
||||
|
@ -304,8 +303,7 @@ const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI) {
|
|||
std::string Buf;
|
||||
raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(Ret.takeError(), OS);
|
||||
OS.flush();
|
||||
report_fatal_error(Buf);
|
||||
report_fatal_error(Twine(OS.str()));
|
||||
}
|
||||
return Ret->data();
|
||||
}
|
||||
|
@ -316,8 +314,7 @@ uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI) {
|
|||
std::string Buf;
|
||||
raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(Ret.takeError(), OS);
|
||||
OS.flush();
|
||||
report_fatal_error(Buf);
|
||||
report_fatal_error(Twine(OS.str()));
|
||||
}
|
||||
return *Ret;
|
||||
}
|
||||
|
|
|
@ -453,7 +453,7 @@ void HexagonMCCodeEmitter::EncodeSingleInstruction(const MCInst &MI,
|
|||
raw_string_ostream Stream(Text);
|
||||
Stream << "Unrecognized relocation combination: width=" << Width
|
||||
<< " kind=" << Kind;
|
||||
report_fatal_error(Stream.str());
|
||||
report_fatal_error(Twine(Stream.str()));
|
||||
}
|
||||
|
||||
/// Some insns are not extended and thus have no bits. These cases require
|
||||
|
|
|
@ -1923,7 +1923,7 @@ NVPTXAsmPrinter::lowerConstantForGV(const Constant *CV, bool ProcessingGeneric)
|
|||
OS << "Unsupported expression in static initializer: ";
|
||||
CE->printAsOperand(OS, /*PrintType=*/false,
|
||||
!MF ? nullptr : MF->getFunction().getParent());
|
||||
report_fatal_error(OS.str());
|
||||
report_fatal_error(Twine(OS.str()));
|
||||
}
|
||||
|
||||
case Instruction::AddrSpaceCast: {
|
||||
|
@ -1937,7 +1937,7 @@ NVPTXAsmPrinter::lowerConstantForGV(const Constant *CV, bool ProcessingGeneric)
|
|||
OS << "Unsupported expression in static initializer: ";
|
||||
CE->printAsOperand(OS, /*PrintType=*/ false,
|
||||
!MF ? nullptr : MF->getFunction().getParent());
|
||||
report_fatal_error(OS.str());
|
||||
report_fatal_error(Twine(OS.str()));
|
||||
}
|
||||
|
||||
case Instruction::GetElementPtr: {
|
||||
|
|
|
@ -282,8 +282,7 @@ ErrorOr<SymbolRef> Decoder::getSymbolForLocation(
|
|||
std::string Buf;
|
||||
llvm::raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(AddressOrErr.takeError(), OS);
|
||||
OS.flush();
|
||||
report_fatal_error(Buf);
|
||||
report_fatal_error(Twine(OS.str()));
|
||||
}
|
||||
// We apply SymbolOffset here directly. We return it separately to allow
|
||||
// the caller to print it as an offset on the symbol name.
|
||||
|
@ -1006,8 +1005,7 @@ bool Decoder::dumpXDataRecord(const COFFObjectFile &COFF,
|
|||
std::string Buf;
|
||||
llvm::raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(Name.takeError(), OS);
|
||||
OS.flush();
|
||||
report_fatal_error(Buf);
|
||||
report_fatal_error(Twine(OS.str()));
|
||||
}
|
||||
|
||||
ListScope EHS(SW, "ExceptionHandler");
|
||||
|
@ -1046,8 +1044,7 @@ bool Decoder::dumpUnpackedEntry(const COFFObjectFile &COFF,
|
|||
std::string Buf;
|
||||
llvm::raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(FunctionNameOrErr.takeError(), OS);
|
||||
OS.flush();
|
||||
report_fatal_error(Buf);
|
||||
report_fatal_error(Twine(OS.str()));
|
||||
}
|
||||
FunctionName = *FunctionNameOrErr;
|
||||
}
|
||||
|
@ -1061,8 +1058,7 @@ bool Decoder::dumpUnpackedEntry(const COFFObjectFile &COFF,
|
|||
std::string Buf;
|
||||
llvm::raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(Name.takeError(), OS);
|
||||
OS.flush();
|
||||
report_fatal_error(Buf);
|
||||
report_fatal_error(Twine(OS.str()));
|
||||
}
|
||||
|
||||
SW.printString("ExceptionRecord",
|
||||
|
@ -1107,8 +1103,7 @@ bool Decoder::dumpPackedEntry(const object::COFFObjectFile &COFF,
|
|||
std::string Buf;
|
||||
llvm::raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(FunctionNameOrErr.takeError(), OS);
|
||||
OS.flush();
|
||||
report_fatal_error(Buf);
|
||||
report_fatal_error(Twine(OS.str()));
|
||||
}
|
||||
FunctionName = *FunctionNameOrErr;
|
||||
}
|
||||
|
@ -1149,8 +1144,7 @@ bool Decoder::dumpPackedARM64Entry(const object::COFFObjectFile &COFF,
|
|||
std::string Buf;
|
||||
llvm::raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(FunctionNameOrErr.takeError(), OS);
|
||||
OS.flush();
|
||||
report_fatal_error(Buf);
|
||||
report_fatal_error(Twine(OS.str()));
|
||||
}
|
||||
FunctionName = *FunctionNameOrErr;
|
||||
}
|
||||
|
|
|
@ -204,8 +204,7 @@ void COFFDumper::dumpSections(unsigned NumSections) {
|
|||
std::string Buf;
|
||||
raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(SymbolNameOrErr.takeError(), OS);
|
||||
OS.flush();
|
||||
report_fatal_error(Buf);
|
||||
report_fatal_error(Twine(OS.str()));
|
||||
}
|
||||
if (SymbolUnique.lookup(*SymbolNameOrErr))
|
||||
Rel.SymbolName = *SymbolNameOrErr;
|
||||
|
|
|
@ -37,7 +37,7 @@ protected:
|
|||
Error.print("", os);
|
||||
|
||||
if (!M)
|
||||
report_fatal_error(os.str());
|
||||
report_fatal_error(Twine(os.str()));
|
||||
}
|
||||
|
||||
::testing::AssertionResult isLibFunc(const Function *FDecl,
|
||||
|
|
|
@ -36,7 +36,7 @@ protected:
|
|||
|
||||
// A failure here means that the test itself is buggy.
|
||||
if (!M)
|
||||
report_fatal_error(os.str());
|
||||
report_fatal_error(Twine(os.str()));
|
||||
|
||||
Function *F = M->getFunction("test");
|
||||
if (F == nullptr)
|
||||
|
|
Loading…
Reference in New Issue