Skip to content

[nfc] Allow forwarding Error returns from Expected callers #92208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/Support/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ template <class T> class [[nodiscard]] Expected {

public:
/// Create an Expected<T> error value from the given Error.
Expected(Error Err)
Expected(Error &&Err)
: HasError(true)
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
// Expected is unchecked upon construction in Debug builds.
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/Bitstream/Reader/BitstreamReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Expected<unsigned> BitstreamCursor::skipRecord(unsigned AbbrevID) {
if (Error Err =
JumpToBit(GetCurrentBitNo() + static_cast<uint64_t>(NumElts) *
EltEnc.getEncodingData()))
return std::move(Err);
return Err;
break;
case BitCodeAbbrevOp::VBR:
assert((unsigned)EltEnc.getEncodingData() <= MaxChunkSize);
Expand All @@ -180,7 +180,7 @@ Expected<unsigned> BitstreamCursor::skipRecord(unsigned AbbrevID) {
break;
case BitCodeAbbrevOp::Char6:
if (Error Err = JumpToBit(GetCurrentBitNo() + NumElts * 6))
return std::move(Err);
return Err;
break;
}
continue;
Expand All @@ -206,7 +206,7 @@ Expected<unsigned> BitstreamCursor::skipRecord(unsigned AbbrevID) {

// Skip over the blob.
if (Error Err = JumpToBit(NewEnd))
return std::move(Err);
return Err;
}
return Code;
}
Expand Down Expand Up @@ -344,7 +344,7 @@ Expected<unsigned> BitstreamCursor::readRecord(unsigned AbbrevID,
// over tail padding first, in case jumping to NewEnd invalidates the Blob
// pointer.
if (Error Err = JumpToBit(NewEnd))
return std::move(Err);
return Err;
const char *Ptr = (const char *)getPointerToBit(CurBitPos, NumElts);

// If we can return a reference to the data, do so to avoid copying it.
Expand Down Expand Up @@ -421,7 +421,7 @@ Error BitstreamCursor::ReadAbbrevRecord() {
Expected<std::optional<BitstreamBlockInfo>>
BitstreamCursor::ReadBlockInfoBlock(bool ReadBlockInfoNames) {
if (llvm::Error Err = EnterSubBlock(bitc::BLOCKINFO_BLOCK_ID))
return std::move(Err);
return Err;

BitstreamBlockInfo NewBlockInfo;

Expand Down Expand Up @@ -452,7 +452,7 @@ BitstreamCursor::ReadBlockInfoBlock(bool ReadBlockInfoNames) {
if (!CurBlockInfo)
return std::nullopt;
if (Error Err = ReadAbbrevRecord())
return std::move(Err);
return Err;

// ReadAbbrevRecord installs the abbrev in CurAbbrevs. Move it to the
// appropriate BlockInfo.
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Object/COFFObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ COFFObjectFile::getSectionContents(DataRefImpl Ref) const {
const coff_section *Sec = toSec(Ref);
ArrayRef<uint8_t> Res;
if (Error E = getSectionContents(Sec, Res))
return std::move(E);
return E;
return Res;
}

Expand Down Expand Up @@ -807,7 +807,7 @@ Expected<std::unique_ptr<COFFObjectFile>>
COFFObjectFile::create(MemoryBufferRef Object) {
std::unique_ptr<COFFObjectFile> Obj(new COFFObjectFile(std::move(Object)));
if (Error E = Obj->initialize())
return std::move(E);
return E;
return std::move(Obj);
}

Expand Down Expand Up @@ -1959,7 +1959,7 @@ ResourceSectionRef::getContents(const coff_resource_data_entry &Entry) {
uint64_t Offset = Entry.DataRVA + Sym->getValue();
ArrayRef<uint8_t> Contents;
if (Error E = Obj->getSectionContents(*Section, Contents))
return std::move(E);
return E;
if (Offset + Entry.DataSize > Contents.size())
return createStringError(object_error::parse_failed,
"data outside of section");
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Object/WindowsResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Expected<ResourceEntryRef>
ResourceEntryRef::create(BinaryStreamRef BSR, const WindowsResource *Owner) {
auto Ref = ResourceEntryRef(BSR, Owner);
if (auto E = Ref.loadNext())
return std::move(E);
return E;
return Ref;
}

Expand Down Expand Up @@ -1006,7 +1006,7 @@ writeWindowsResourceCOFF(COFF::MachineTypes MachineType,
Error E = Error::success();
WindowsResourceCOFFWriter Writer(MachineType, Parser, E);
if (E)
return std::move(E);
return E;
return Writer.write(TimeDateStamp);
}

Expand Down
Loading