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.
const Elf_Shdr *getRelSection(DataRefImpl Rel) const {
auto RelSecOrErr = EF.getSection(Rel.d.a);
if (!RelSecOrErr)
- report_fatal_error(errorToErrorCode(RelSecOrErr.takeError()).message());
+ report_fatal_error(
+ Twine(errorToErrorCode(RelSecOrErr.takeError()).message()));
return *RelSecOrErr;
}
// Error check sh_link here so that getRelocationSymbol can just use it.
auto SymSecOrErr = EF.getSection(RelSec->sh_link);
if (!SymSecOrErr)
- report_fatal_error(errorToErrorCode(SymSecOrErr.takeError()).message());
+ report_fatal_error(
+ Twine(errorToErrorCode(SymSecOrErr.takeError()).message()));
RelData.d.b += S->sh_size / S->sh_entsize;
return relocation_iterator(RelocationRef(RelData, this));
assert(getRelSection(Rel)->sh_type == ELF::SHT_REL);
auto Ret = EF.template getEntry<Elf_Rel>(Rel.d.a, Rel.d.b);
if (!Ret)
- report_fatal_error(errorToErrorCode(Ret.takeError()).message());
+ report_fatal_error(Twine(errorToErrorCode(Ret.takeError()).message()));
return *Ret;
}
assert(getRelSection(Rela)->sh_type == ELF::SHT_RELA);
auto Ret = EF.template getEntry<Elf_Rela>(Rela.d.a, Rela.d.b);
if (!Ret)
- report_fatal_error(errorToErrorCode(Ret.takeError()).message());
+ report_fatal_error(Twine(errorToErrorCode(Ret.takeError()).message()));
return *Ret;
}
[[noreturn]] inline void ReportLastErrorFatal(const char *Msg) {
std::string ErrMsg;
MakeErrMsg(&ErrMsg, Msg);
- llvm::report_fatal_error(ErrMsg);
+ llvm::report_fatal_error(Twine(ErrMsg));
}
template <typename HandleTraits>
if (Error Err = IndexCursor.JumpToBit(
GlobalMetadataBitPosIndex[ID - MDStringRef.size()]))
report_fatal_error("lazyLoadOneMetadata failed jumping: " +
- toString(std::move(Err)));
+ Twine(toString(std::move(Err))));
Expected<BitstreamEntry> MaybeEntry = IndexCursor.advanceSkippingSubblocks();
if (!MaybeEntry)
// FIXME this drops the error on the floor.
report_fatal_error("lazyLoadOneMetadata failed advanceSkippingSubblocks: " +
- toString(MaybeEntry.takeError()));
+ Twine(toString(MaybeEntry.takeError())));
BitstreamEntry Entry = MaybeEntry.get();
++NumMDRecordLoaded;
if (Expected<unsigned> MaybeCode =
if (Error Err =
parseOneMetadata(Record, MaybeCode.get(), Placeholders, Blob, ID))
report_fatal_error("Can't lazyload MD, parseOneMetadata: " +
- toString(std::move(Err)));
+ Twine(toString(std::move(Err))));
} else
- report_fatal_error("Can't lazyload MD: " + toString(MaybeCode.takeError()));
+ report_fatal_error("Can't lazyload MD: " +
+ Twine(toString(MaybeCode.takeError())));
}
/// Ensure that all forward-references and placeholders are resolved.
R << (" (in function: " + MF.getName() + ")").str();
if (TPC.isGlobalISelAbortEnabled())
- report_fatal_error(R.getMsg());
+ report_fatal_error(Twine(R.getMsg()));
else
ORE.emit(R);
}
R << (" (in function: " + MF.getName() + ")").str();
if (IsFatal)
- report_fatal_error(R.getMsg());
+ report_fatal_error(Twine(R.getMsg()));
else
MORE.emit(R);
}
R << (" (in function: " + MF.getName() + ")").str();
if (ShouldAbort)
- report_fatal_error(R.getMsg());
+ report_fatal_error(Twine(R.getMsg()));
ORE.emit(R);
}
else
Msg << "unknown intrinsic #" << iid;
}
- report_fatal_error(Msg.str());
+ report_fatal_error(Twine(Msg.str()));
}
char SelectionDAGISel::ID = 0;
uint64_t Addr = getSymbolAddress(Name);
if (!Addr && AbortOnFailure)
- report_fatal_error("Program used external function '" + Name +
+ report_fatal_error(Twine("Program used external function '") + Name +
"' which could not be resolved!");
return (void*)Addr;
Expected<section_iterator> RelSecOrErr = SI->getRelocatedSection();
if (!RelSecOrErr)
- report_fatal_error(toString(RelSecOrErr.takeError()));
+ report_fatal_error(Twine(toString(RelSecOrErr.takeError())));
section_iterator RelSecI = *RelSecOrErr;
if (!(RelSecI == Section))
// FIXME: Implement error handling that doesn't kill the host program!
if (!Addr && !Resolver.allowsZeroSymbols())
- report_fatal_error("Program used external function '" + Name +
+ report_fatal_error(Twine("Program used external function '") + Name +
"' which could not be resolved!");
// If Resolver returned UINT64_MAX, the client wants to handle this symbol
Expected<section_iterator> RelSecOrErr = si->getRelocatedSection();
if (!RelSecOrErr)
- report_fatal_error(toString(RelSecOrErr.takeError()));
+ report_fatal_error(Twine(toString(RelSecOrErr.takeError())));
section_iterator RelSecI = *RelSecOrErr;
if (RelSecI == Obj.section_end())
Pattern = std::make_shared<Regex>(Val);
std::string RegexError;
if (!Pattern->isValid(RegexError))
- report_fatal_error("Invalid regular expression '" + Val +
+ report_fatal_error(Twine("Invalid regular expression '") + Val +
"' in -pass-remarks: " + RegexError,
false);
}
///
bool FunctionPassManager::run(Function &F) {
handleAllErrors(F.materialize(), [&](ErrorInfoBase &EIB) {
- report_fatal_error("Error reading bitcode file: " + EIB.message());
+ report_fatal_error(Twine("Error reading bitcode file: ") + EIB.message());
});
return FPM->run(F);
}
// Parse a custom AA pipeline if asked to.
if (!Conf.AAPipeline.empty()) {
if (auto Err = PB.parseAAPipeline(AA, Conf.AAPipeline)) {
- report_fatal_error("unable to parse AA pipeline description '" +
+ report_fatal_error(Twine("unable to parse AA pipeline description '") +
Conf.AAPipeline + "': " + toString(std::move(Err)));
}
} else {
// Parse a custom pipeline if asked to.
if (!Conf.OptPipeline.empty()) {
if (auto Err = PB.parsePassPipeline(MPM, Conf.OptPipeline)) {
- report_fatal_error("unable to parse pass pipeline description '" +
+ report_fatal_error(Twine("unable to parse pass pipeline description '") +
Conf.OptPipeline + "': " + toString(std::move(Err)));
}
} else if (IsThinLTO) {
if (!Conf.DwoDir.empty()) {
std::error_code EC;
if (auto EC = llvm::sys::fs::create_directories(Conf.DwoDir))
- report_fatal_error("Failed to create directory " + Conf.DwoDir + ": " +
- EC.message());
+ report_fatal_error(Twine("Failed to create directory ") + Conf.DwoDir +
+ ": " + EC.message());
DwoFile = Conf.DwoDir;
sys::path::append(DwoFile, std::to_string(Task) + ".dwo");
std::error_code EC;
DwoOut = std::make_unique<ToolOutputFile>(DwoFile, EC, sys::fs::OF_None);
if (EC)
- report_fatal_error("Failed to open " + DwoFile + ": " + EC.message());
+ report_fatal_error(Twine("Failed to open ") + DwoFile + ": " +
+ EC.message());
}
auto Stream = AddStream(Task);
auto InputOrError = lto::InputFile::create(Buffer);
if (!InputOrError)
- report_fatal_error("ThinLTO cannot create input file: " +
+ report_fatal_error(Twine("ThinLTO cannot create input file: ") +
toString(InputOrError.takeError()));
auto TripleStr = (*InputOrError)->getTargetTriple();
const Target *TheTarget =
TargetRegistry::lookupTarget(TheTriple.str(), ErrMsg);
if (!TheTarget) {
- report_fatal_error("Can't load target for this Triple: " + ErrMsg);
+ report_fatal_error(Twine("Can't load target for this Triple: ") + ErrMsg);
}
// Use MAttr as the default set of features.
std::error_code Err;
raw_fd_ostream OS(OutputPath, Err, sys::fs::OF_None);
if (Err)
- report_fatal_error("Can't open output '" + OutputPath + "'\n");
+ report_fatal_error(Twine("Can't open output '") + OutputPath + "'\n");
OS << OutputBuffer.getBuffer();
return std::string(OutputPath.str());
}
bool IsDir;
sys::fs::is_directory(SavedObjectsDirectoryPath, IsDir);
if (!IsDir)
- report_fatal_error("Unexistent dir: '" + SavedObjectsDirectoryPath + "'");
+ report_fatal_error(Twine("Unexistent dir: '") + SavedObjectsDirectoryPath + "'");
ProducedBinaryFiles.resize(Modules.size());
}
SwitchSection(P.first, P.second);
} else {
if(Symbol->declareCommon(Size, ByteAlignment))
- report_fatal_error("Symbol: " + Symbol->getName() +
+ report_fatal_error(Twine("Symbol: ") + Symbol->getName() +
" redeclared as different type");
}
*MCOffset, "BFD_RELOC_NONE", SRE, SRE->getLoc(),
*getContext().getSubtargetInfo()))
report_fatal_error("Relocation for CG Profile could not be created: " +
- Err->second);
+ Twine(Err->second));
}
void MCELFStreamer::finalizeCGProfile() {
static int64_t getELFAddend(RelocationRef R) {
Expected<int64_t> AddendOrErr = ELFRelocationRef(R).getAddend();
handleAllErrors(AddendOrErr.takeError(), [](const ErrorInfoBase &EI) {
- report_fatal_error(EI.message());
+ report_fatal_error(Twine(EI.message()));
});
return *AddendOrErr;
}
EC = EI.convertToErrorCode();
});
if (EC == inconvertibleErrorCode())
- report_fatal_error(EC.message());
+ report_fatal_error(Twine(EC.message()));
return EC;
}
raw_string_ostream ErrStream(ErrMsg);
logAllUnhandledErrors(std::move(Err), ErrStream);
}
- report_fatal_error(ErrMsg);
+ report_fatal_error(Twine(ErrMsg));
}
} // end namespace llvm
std::string Error;
if (auto SCL = create(Paths, FS, Error))
return SCL;
- report_fatal_error(Error);
+ report_fatal_error(Twine(Error));
}
bool SpecialCaseList::createInternal(const std::vector<std::string> &Paths,
// has_error() and clear the error flag with clear_error() before
// destructing raw_ostream objects which may have errors.
if (has_error())
- report_fatal_error("IO failure on output stream: " + error().message(),
+ report_fatal_error(Twine("IO failure on output stream: ") +
+ error().message(),
/*gen_crash_diag=*/false);
}
} else if (Processor == "gfx801") {
if (!isXnackOnOrAny())
report_fatal_error(
- "AMD GPU code object V2 does not support processor " + Processor +
- " without XNACK");
+ "AMD GPU code object V2 does not support processor " +
+ Twine(Processor) + " without XNACK");
} else if (Processor == "gfx802") {
} else if (Processor == "gfx803") {
} else if (Processor == "gfx805") {
} else if (Processor == "gfx810") {
if (!isXnackOnOrAny())
report_fatal_error(
- "AMD GPU code object V2 does not support processor " + Processor +
- " without XNACK");
+ "AMD GPU code object V2 does not support processor " +
+ Twine(Processor) + " without XNACK");
} else if (Processor == "gfx900") {
if (isXnackOnOrAny())
Processor = "gfx901";
} else if (Processor == "gfx90c") {
if (isXnackOnOrAny())
report_fatal_error(
- "AMD GPU code object V2 does not support processor " + Processor +
- " with XNACK being ON or ANY");
+ "AMD GPU code object V2 does not support processor " +
+ Twine(Processor) + " with XNACK being ON or ANY");
} else {
report_fatal_error(
- "AMD GPU code object V2 does not support processor " + Processor);
+ "AMD GPU code object V2 does not support processor " +
+ Twine(Processor));
}
break;
case ELF::ELFABIVERSION_AMDGPU_HSA_V3:
DebugLoc Empty;
const DebugLoc &DL = MI.getDebugLoc();
if (DL != Empty)
- report_fatal_error("line " + std::to_string(DL.getLine()) +
+ report_fatal_error(Twine("line ") + std::to_string(DL.getLine()) +
": Invalid usage of the XADD return value", false);
else
report_fatal_error("Invalid usage of the XADD return value", false);
switch (MI.getOpcode()) {
default:
- report_fatal_error(std::string("Unknown .new type: ") +
- std::to_string(MI.getOpcode()));
+ report_fatal_error(Twine("Unknown .new type: ") +
+ std::to_string(MI.getOpcode()));
case Hexagon::S4_storerb_ur:
return Hexagon::S4_storerbnew_ur;
"Emscripten EH/SjLj does not support multivalue returns: " +
std::string(F->getName()) + ": " +
WebAssembly::signatureToString(Sig);
- report_fatal_error(Msg);
+ report_fatal_error(Twine(Msg));
}
WasmSym = cast<MCSymbolWasm>(
GetExternalSymbolSymbol(getEmscriptenInvokeSymbolName(Sig)));
OptimizeDL = llvm::sys::DynamicLibrary::getPermanentLibrary(
OptimizePluginPath.c_str(), &ErrorMsg);
if (!ErrorMsg.empty())
- report_fatal_error("Failed to load opt plugin: \"" + ErrorMsg + '\"');
+ report_fatal_error(Twine("Failed to load opt plugin: \"") + ErrorMsg +
+ "\"");
OptimizeCut = (OptimizeCutT)OptimizeDL.getAddressOfSymbol("optimize_cut");
if (!OptimizeCut)
report_fatal_error("Invalid optimization plugin");
std::move(SrcModule), GlobalsToImport.getArrayRef(),
[](GlobalValue &, IRMover::ValueAdder) {},
/*IsPerformingImport=*/true))
- report_fatal_error("Function Import: link error: " +
+ report_fatal_error(Twine("Function Import: link error: ") +
toString(std::move(Err)));
ImportedCount += GlobalsToImport.size();
Pos = Asm.find("@");
if (Pos == std::string::npos)
- report_fatal_error("unsupported .symver: " + Asm);
+ report_fatal_error(Twine("unsupported .symver: ", Asm));
Asm.replace(Pos, 1, Suffix + "@");
GV->getParent()->setModuleInlineAsm(Asm);
Options.Atomic = AtomicCounter;
if (DefaultGCOVVersion.size() != 4) {
- llvm::report_fatal_error(std::string("Invalid -default-gcov-version: ") +
+ llvm::report_fatal_error(Twine("Invalid -default-gcov-version: ") +
DefaultGCOVVersion);
}
memcpy(Options.Version, DefaultGCOVVersion.c_str(), 4);
std::string CompressedNameStr;
if (Error E = collectPGOFuncNameStrings(ReferencedNames, CompressedNameStr,
DoInstrProfNameCompression)) {
- report_fatal_error(toString(std::move(E)), false);
+ report_fatal_error(Twine(toString(std::move(E))), false);
}
auto &Ctx = M->getContext();
std::string Name = Regex(Pattern).sub(Transform, C.getName(), &Error);
if (!Error.empty())
- report_fatal_error("unable to transforn " + C.getName() + " in " +
+ report_fatal_error(Twine("unable to transforn ") + C.getName() + " in " +
M.getModuleIdentifier() + ": " + Error);
if (C.getName() == Name)
MemoryBuffer::getFile(MapFile);
if (!Mapping)
- report_fatal_error("unable to read rewrite map '" + MapFile + "': " +
- Mapping.getError().message());
+ report_fatal_error(Twine("unable to read rewrite map '") + MapFile +
+ "': " + Mapping.getError().message());
if (!parse(*Mapping, DL))
- report_fatal_error("unable to parse rewrite map '" + MapFile + "'");
+ report_fatal_error(Twine("unable to parse rewrite map '") + MapFile + "'");
return true;
}
std::make_unique<TrackingSectionMemoryManager>(&CodeSize))
.create(TM.release()));
if (!ExecEngine)
- report_fatal_error(Error);
+ report_fatal_error(Twine(Error));
// Adding the generated object file containing the assembled function.
// The ExecutionEngine makes sure the object file is copied into an
// executable page.
ExitOnErr(getModuleSummaryIndexForFile(Filename));
// Skip files without a module summary.
if (!Index)
- report_fatal_error(Filename + " does not contain an index");
+ report_fatal_error(Twine(Filename) + " does not contain an index");
unsigned Calls = 0, Refs = 0, Functions = 0, Alias = 0, Globals = 0;
for (auto &Summaries : *Index) {
const object::ELFSectionRef &Sec) {
auto PhdrRangeOrErr = Obj.program_headers();
if (!PhdrRangeOrErr)
- report_fatal_error(toString(PhdrRangeOrErr.takeError()));
+ report_fatal_error(Twine(toString(PhdrRangeOrErr.takeError())));
// Search for a PT_LOAD segment containing the requested section. Use this
// segment's p_addr to calculate the section's LMA.
auto Ret = ELF.getSection(*Symbol, SymTab, ShndxTable);
if (!Ret)
- report_fatal_error(errorToErrorCode(Ret.takeError()).message());
+ report_fatal_error(Twine(errorToErrorCode(Ret.takeError()).message()));
return *Ret;
}
}
sys::Memory::MF_WRITE,
EC);
if (!MB.base())
- report_fatal_error("Can't allocate enough memory: " + EC.message());
+ report_fatal_error(Twine("Can't allocate enough memory: ") +
+ EC.message());
PreallocSlab = MB;
UsePreallocation = true;
sys::Memory::MF_WRITE,
EC);
if (!MB.base())
- report_fatal_error("MemoryManager allocation failed: " + EC.message());
+ report_fatal_error(Twine("MemoryManager allocation failed: ") +
+ EC.message());
FunctionMemory.push_back(SectionInfo(SectionName, MB, SectionID));
return (uint8_t*)MB.base();
}
sys::Memory::MF_WRITE,
EC);
if (!MB.base())
- report_fatal_error("MemoryManager allocation failed: " + EC.message());
+ report_fatal_error(Twine("MemoryManager allocation failed: ") +
+ EC.message());
DataMemory.push_back(SectionInfo(SectionName, MB, SectionID));
return (uint8_t*)MB.base();
}
static void loadDylibs() {
for (const std::string &Dylib : Dylibs) {
if (!sys::fs::is_regular_file(Dylib))
- report_fatal_error("Dylib not found: '" + Dylib + "'.");
+ report_fatal_error(Twine("Dylib not found: '") + Dylib + "'.");
std::string ErrMsg;
if (sys::DynamicLibrary::LoadLibraryPermanently(Dylib.c_str(), &ErrMsg))
- report_fatal_error("Error loading '" + Dylib + "': " + ErrMsg);
+ report_fatal_error(Twine("Error loading '") + Dylib + "': " + ErrMsg);
}
}
size_t EqualsIdx = Mapping.find_first_of('=');
if (EqualsIdx == StringRef::npos)
- report_fatal_error("Invalid dummy symbol specification '" + Mapping +
- "'. Should be '<symbol name>=<addr>'");
+ report_fatal_error(Twine("Invalid dummy symbol specification '") +
+ Mapping + "'. Should be '<symbol name>=<addr>'");
std::string Symbol = Mapping.substr(0, EqualsIdx);
std::string AddrStr = Mapping.substr(EqualsIdx + 1);
uint64_t Addr;
if (StringRef(AddrStr).getAsInteger(0, Addr))
- report_fatal_error("Invalid symbol mapping '" + Mapping + "'.");
+ report_fatal_error(Twine("Invalid symbol mapping '") + Mapping + "'.");
MemMgr.addDummySymbol(Symbol, Addr);
}