Skip to content

Commit d02c167

Browse files
committed
[Support][Error] Add ErrorAsOutParameter constructor that takes an Error by ref.
ErrorAsOutParameter's Error* constructor supports cases where an Error might not be passed in (because in the calling context it's known that this call won't fail). Most clients always have an Error present however, and for them an Error& overload is more convenient.
1 parent 8fcbba8 commit d02c167

20 files changed

+28
-23
lines changed

llvm/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ template <typename ORCABI> class LocalTrampolinePool : public TrampolinePool {
135135
LocalTrampolinePool(ResolveLandingFunction ResolveLanding, Error &Err)
136136
: ResolveLanding(std::move(ResolveLanding)) {
137137

138-
ErrorAsOutParameter _(&Err);
138+
ErrorAsOutParameter _(Err);
139139

140140
/// Try to set up the resolver block.
141141
std::error_code EC;
@@ -262,7 +262,7 @@ class LocalJITCompileCallbackManager : public JITCompileCallbackManager {
262262
using NotifyLandingResolvedFunction =
263263
TrampolinePool::NotifyLandingResolvedFunction;
264264

265-
ErrorAsOutParameter _(&Err);
265+
ErrorAsOutParameter _(Err);
266266
auto TP = LocalTrampolinePool<ORCABI>::Create(
267267
[this](ExecutorAddr TrampolineAddr,
268268
NotifyLandingResolvedFunction NotifyLandingResolved) {

llvm/include/llvm/Object/ELF.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ class ELFFile {
401401
/// be checked after iteration ends.
402402
Elf_Note_Iterator notes_begin(const Elf_Phdr &Phdr, Error &Err) const {
403403
assert(Phdr.p_type == ELF::PT_NOTE && "Phdr is not of type PT_NOTE");
404-
ErrorAsOutParameter ErrAsOutParam(&Err);
404+
ErrorAsOutParameter ErrAsOutParam(Err);
405405
if (Phdr.p_offset + Phdr.p_filesz > getBufSize()) {
406406
Err =
407407
createError("invalid offset (0x" + Twine::utohexstr(Phdr.p_offset) +
@@ -429,7 +429,7 @@ class ELFFile {
429429
/// be checked after iteration ends.
430430
Elf_Note_Iterator notes_begin(const Elf_Shdr &Shdr, Error &Err) const {
431431
assert(Shdr.sh_type == ELF::SHT_NOTE && "Shdr is not of type SHT_NOTE");
432-
ErrorAsOutParameter ErrAsOutParam(&Err);
432+
ErrorAsOutParameter ErrAsOutParam(Err);
433433
if (Shdr.sh_offset + Shdr.sh_size > getBufSize()) {
434434
Err =
435435
createError("invalid offset (0x" + Twine::utohexstr(Shdr.sh_offset) +

llvm/include/llvm/Support/Error.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,12 +1129,17 @@ inline bool errorToBool(Error Err) {
11291129
/// function.
11301130
class ErrorAsOutParameter {
11311131
public:
1132+
11321133
ErrorAsOutParameter(Error *Err) : Err(Err) {
11331134
// Raise the checked bit if Err is success.
11341135
if (Err)
11351136
(void)!!*Err;
11361137
}
11371138

1139+
ErrorAsOutParameter(Error &Err) : Err(&Err) {
1140+
(void)!!Err;
1141+
}
1142+
11381143
~ErrorAsOutParameter() {
11391144
// Clear the checked bit.
11401145
if (Err && !*Err)

llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class COFFLinkGraphLowering_x86_64 {
256256
Error Err = Error::success();
257257
Ctx.lookup(Symbols,
258258
createLookupContinuation([&](Expected<AsyncLookupResult> LR) {
259-
ErrorAsOutParameter EAO(&Err);
259+
ErrorAsOutParameter _(Err);
260260
if (!LR) {
261261
Err = LR.takeError();
262262
return;

llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ COFFPlatform::COFFPlatform(
399399
OrcRuntimeArchive(std::move(OrcRuntimeArchive)),
400400
StaticVCRuntime(StaticVCRuntime),
401401
COFFHeaderStartSymbol(ES.intern("__ImageBase")) {
402-
ErrorAsOutParameter _(&Err);
402+
ErrorAsOutParameter _(Err);
403403

404404
Bootstrapping.store(true);
405405
ObjLinkingLayer.addPlugin(std::make_unique<COFFPlatformPlugin>(*this));

llvm/lib/ExecutionEngine/Orc/Core.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,7 +1809,7 @@ ExecutionSession::lookup(const JITDylibSearchOrder &SearchOrder,
18091809
if (R)
18101810
PromisedResult.set_value(std::move(*R));
18111811
else {
1812-
ErrorAsOutParameter _(&ResolutionError);
1812+
ErrorAsOutParameter _(ResolutionError);
18131813
ResolutionError = R.takeError();
18141814
PromisedResult.set_value(SymbolMap());
18151815
}
@@ -1820,7 +1820,7 @@ ExecutionSession::lookup(const JITDylibSearchOrder &SearchOrder,
18201820
Error ResolutionError = Error::success();
18211821

18221822
auto NotifyComplete = [&](Expected<SymbolMap> R) {
1823-
ErrorAsOutParameter _(&ResolutionError);
1823+
ErrorAsOutParameter _(ResolutionError);
18241824
if (R)
18251825
Result = std::move(*R);
18261826
else

llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ static bool isDwarfSection(StringRef SectionName) {
234234

235235
std::unique_ptr<WritableMemoryBuffer>
236236
ELFDebugObject::CopyBuffer(MemoryBufferRef Buffer, Error &Err) {
237-
ErrorAsOutParameter _(&Err);
237+
ErrorAsOutParameter _(Err);
238238
size_t Size = Buffer.getBufferSize();
239239
StringRef Name = Buffer.getBufferIdentifier();
240240
if (auto Copy = WritableMemoryBuffer::getNewUninitMemBuffer(Size, Name)) {

llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ ELFNixPlatform::ELFNixPlatform(
396396
: ES(ObjLinkingLayer.getExecutionSession()), PlatformJD(PlatformJD),
397397
ObjLinkingLayer(ObjLinkingLayer),
398398
DSOHandleSymbol(ES.intern("__dso_handle")) {
399-
ErrorAsOutParameter _(&Err);
399+
ErrorAsOutParameter _(Err);
400400
ObjLinkingLayer.addPlugin(std::make_unique<ELFNixPlatformPlugin>(*this));
401401

402402
PlatformJD.addGenerator(std::move(OrcRuntimeGenerator));

llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ StaticLibraryDefinitionGenerator::StaticLibraryDefinitionGenerator(
467467
GetObjectFileInterface GetObjFileInterface, Error &Err)
468468
: L(L), GetObjFileInterface(std::move(GetObjFileInterface)),
469469
ArchiveBuffer(std::move(ArchiveBuffer)), Archive(std::move(Archive)) {
470-
ErrorAsOutParameter _(&Err);
470+
ErrorAsOutParameter _(Err);
471471
if (!this->GetObjFileInterface)
472472
this->GetObjFileInterface = getObjectFileInterface;
473473
if (!Err)

llvm/lib/ExecutionEngine/Orc/LLJIT.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ LLJIT::createCompileFunction(LLJITBuilderState &S,
10061006
LLJIT::LLJIT(LLJITBuilderState &S, Error &Err)
10071007
: DL(std::move(*S.DL)), TT(S.JTMB->getTargetTriple()) {
10081008

1009-
ErrorAsOutParameter _(&Err);
1009+
ErrorAsOutParameter _(Err);
10101010

10111011
assert(!(S.EPC && S.ES) && "EPC and ES should not both be set");
10121012

llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ MachOPlatform::MachOPlatform(
477477
: ES(ObjLinkingLayer.getExecutionSession()), PlatformJD(PlatformJD),
478478
ObjLinkingLayer(ObjLinkingLayer),
479479
BuildMachOHeaderMU(std::move(BuildMachOHeaderMU)) {
480-
ErrorAsOutParameter _(&Err);
480+
ErrorAsOutParameter _(Err);
481481
ObjLinkingLayer.addPlugin(std::make_unique<MachOPlatformPlugin>(*this));
482482
PlatformJD.addGenerator(std::move(OrcRuntimeGenerator));
483483

llvm/lib/Object/Archive.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ void Archive::setFirstRegular(const Child &C) {
707707

708708
Archive::Archive(MemoryBufferRef Source, Error &Err)
709709
: Binary(Binary::ID_Archive, Source) {
710-
ErrorAsOutParameter ErrAsOutParam(&Err);
710+
ErrorAsOutParameter ErrAsOutParam(Err);
711711
StringRef Buffer = Data.getBuffer();
712712
// Check for sufficient magic.
713713
if (Buffer.starts_with(ThinArchiveMagic)) {

llvm/lib/Object/GOFFObjectFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ObjectFile::createGOFFObjectFile(MemoryBufferRef Object) {
3535

3636
GOFFObjectFile::GOFFObjectFile(MemoryBufferRef Object, Error &Err)
3737
: ObjectFile(Binary::ID_GOFF, Object) {
38-
ErrorAsOutParameter ErrAsOutParam(&Err);
38+
ErrorAsOutParameter ErrAsOutParam(Err);
3939
// Object file isn't the right size, bail out early.
4040
if ((Object.getBufferSize() % GOFF::RecordLength) != 0) {
4141
Err = createStringError(

llvm/lib/Object/MachOObjectFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian,
12701270
size_t MachOFilesetEntryOffset)
12711271
: ObjectFile(getMachOType(IsLittleEndian, Is64bits), Object),
12721272
MachOFilesetEntryOffset(MachOFilesetEntryOffset) {
1273-
ErrorAsOutParameter ErrAsOutParam(&Err);
1273+
ErrorAsOutParameter ErrAsOutParam(Err);
12741274
uint64_t SizeOfHeaders;
12751275
uint32_t cputype;
12761276
if (is64Bit()) {

llvm/lib/Object/MachOUniversal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ MachOUniversalBinary::create(MemoryBufferRef Source) {
131131
MachOUniversalBinary::MachOUniversalBinary(MemoryBufferRef Source, Error &Err)
132132
: Binary(Binary::ID_MachOUniversalBinary, Source), Magic(0),
133133
NumberOfObjects(0) {
134-
ErrorAsOutParameter ErrAsOutParam(&Err);
134+
ErrorAsOutParameter ErrAsOutParam(Err);
135135
if (Data.getBufferSize() < sizeof(MachO::fat_header)) {
136136
Err = make_error<GenericBinaryError>("File too small to be a Mach-O "
137137
"universal file",

llvm/lib/Object/Minidump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ MinidumpFile::create(MemoryBufferRef Source) {
145145

146146
iterator_range<MinidumpFile::FallibleMemory64Iterator>
147147
MinidumpFile::getMemory64List(Error &Err) const {
148-
ErrorAsOutParameter ErrAsOutParam(&Err);
148+
ErrorAsOutParameter ErrAsOutParam(Err);
149149
auto end = FallibleMemory64Iterator::end(Memory64Iterator::end());
150150
Expected<minidump::Memory64ListHeader> ListHeader = getMemoryList64Header();
151151
if (!ListHeader) {

llvm/lib/Object/TapiUniversal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ using namespace object;
2222
TapiUniversal::TapiUniversal(MemoryBufferRef Source, Error &Err)
2323
: Binary(ID_TapiUniversal, Source) {
2424
Expected<std::unique_ptr<InterfaceFile>> Result = TextAPIReader::get(Source);
25-
ErrorAsOutParameter ErrAsOuParam(&Err);
25+
ErrorAsOutParameter ErrAsOuParam(Err);
2626
if (!Result) {
2727
Err = Result.takeError();
2828
return;

llvm/lib/Object/WasmObjectFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ static Error readSection(WasmSection &Section, WasmObjectFile::ReadContext &Ctx,
344344

345345
WasmObjectFile::WasmObjectFile(MemoryBufferRef Buffer, Error &Err)
346346
: ObjectFile(Binary::ID_Wasm, Buffer) {
347-
ErrorAsOutParameter ErrAsOutParam(&Err);
347+
ErrorAsOutParameter ErrAsOutParam(Err);
348348
Header.Magic = getData().substr(0, 4);
349349
if (Header.Magic != StringRef("\0asm", 4)) {
350350
Err = make_error<StringError>("invalid magic number",

llvm/lib/Object/XCOFFObjectFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ TBVectorExt::TBVectorExt(StringRef TBvectorStrRef, Error &Err) {
14141414
unsigned ParmsNum =
14151415
GETVALUEWITHMASKSHIFT(NumberOfVectorParmsMask, NumberOfVectorParmsShift);
14161416

1417-
ErrorAsOutParameter EAO(&Err);
1417+
ErrorAsOutParameter EAO(Err);
14181418
Expected<SmallString<32>> VecParmsTypeOrError =
14191419
parseVectorParmsType(VecParmsTypeValue, ParmsNum);
14201420
if (!VecParmsTypeOrError)
@@ -1458,7 +1458,7 @@ XCOFFTracebackTable::create(const uint8_t *Ptr, uint64_t &Size, bool Is64Bit) {
14581458
XCOFFTracebackTable::XCOFFTracebackTable(const uint8_t *Ptr, uint64_t &Size,
14591459
Error &Err, bool Is64Bit)
14601460
: TBPtr(Ptr), Is64BitObj(Is64Bit) {
1461-
ErrorAsOutParameter EAO(&Err);
1461+
ErrorAsOutParameter EAO(Err);
14621462
DataExtractor DE(ArrayRef<uint8_t>(Ptr, Size), /*IsLittleEndian=*/false,
14631463
/*AddressSize=*/0);
14641464
DataExtractor::Cursor Cur(/*Offset=*/0);

llvm/lib/Support/DataExtractor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ int64_t DataExtractor::getSLEB128(uint64_t *offset_ptr, Error *Err) const {
227227
}
228228

229229
void DataExtractor::skip(Cursor &C, uint64_t Length) const {
230-
ErrorAsOutParameter ErrAsOut(&C.Err);
230+
ErrorAsOutParameter ErrAsOut(C.Err);
231231
if (isError(&C.Err))
232232
return;
233233

0 commit comments

Comments
 (0)