Author: Duncan P. N. Exon Smith Date: 2021-10-22T12:40:10-07:00 New Revision: 2410fb4616b2c08bbaddd44e6c11da8285fbd1d3
URL: https://github.com/llvm/llvm-project/commit/2410fb4616b2c08bbaddd44e6c11da8285fbd1d3 DIFF: https://github.com/llvm/llvm-project/commit/2410fb4616b2c08bbaddd44e6c11da8285fbd1d3.diff LOG: Support: Use Expected<T>::moveInto() in a few places These are some usage examples for `Expected<T>::moveInto()`. Differential Revision: https://reviews.llvm.org/D112280 Added: Modified: clang/lib/CodeGen/BackendUtil.cpp llvm/lib/Bitcode/Reader/BitcodeReader.cpp llvm/lib/DebugInfo/Symbolize/Symbolize.cpp llvm/lib/Object/ObjectFile.cpp llvm/lib/XRay/InstrumentationMap.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index ff76ef1d9dd8..30f81b8ae473 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1657,16 +1657,17 @@ void clang::EmitBackendOutput(DiagnosticsEngine &Diags, // If we are performing a ThinLTO importing compile, load the function index // into memory and pass it into runThinLTOBackend, which will run the // function importer and invoke LTO passes. - Expected<std::unique_ptr<ModuleSummaryIndex>> IndexOrErr = - llvm::getModuleSummaryIndexForFile(CGOpts.ThinLTOIndexFile, - /*IgnoreEmptyThinLTOIndexFile*/true); - if (!IndexOrErr) { - logAllUnhandledErrors(IndexOrErr.takeError(), errs(), + std::unique_ptr<ModuleSummaryIndex> CombinedIndex; + if (Error E = llvm::getModuleSummaryIndexForFile( + CGOpts.ThinLTOIndexFile, + /*IgnoreEmptyThinLTOIndexFile*/ true) + .moveInto(CombinedIndex)) { + logAllUnhandledErrors(std::move(E), errs(), "Error loading index file '" + CGOpts.ThinLTOIndexFile + "': "); return; } - std::unique_ptr<ModuleSummaryIndex> CombinedIndex = std::move(*IndexOrErr); + // A null CombinedIndex means we should skip ThinLTO compilation // (LLVM will optionally ignore empty index files, returning null instead // of an error). diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 349d40e1a63c..301145939904 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -179,10 +179,8 @@ static Expected<std::string> readIdentificationBlock(BitstreamCursor &Stream) { while (true) { BitstreamEntry Entry; - if (Expected<BitstreamEntry> Res = Stream.advance()) - Entry = Res.get(); - else - return Res.takeError(); + if (Error E = Stream.advance().moveInto(Entry)) + return std::move(E); switch (Entry.Kind) { default: @@ -226,10 +224,8 @@ static Expected<std::string> readIdentificationCode(BitstreamCursor &Stream) { return ""; BitstreamEntry Entry; - if (Expected<BitstreamEntry> Res = Stream.advance()) - Entry = std::move(Res.get()); - else - return Res.takeError(); + if (Error E = Stream.advance().moveInto(Entry)) + return std::move(E); switch (Entry.Kind) { case BitstreamEntry::EndBlock: @@ -305,10 +301,8 @@ static Expected<bool> hasObjCCategory(BitstreamCursor &Stream) { // need to understand them all. while (true) { BitstreamEntry Entry; - if (Expected<BitstreamEntry> Res = Stream.advance()) - Entry = std::move(Res.get()); - else - return Res.takeError(); + if (Error E = Stream.advance().moveInto(Entry)) + return std::move(E); switch (Entry.Kind) { case BitstreamEntry::Error: diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp index 6da0b6907786..f3f09584fdc9 100644 --- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp +++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp @@ -280,10 +280,7 @@ bool getGNUDebuglinkContents(const ObjectFile *Obj, std::string &DebugName, return false; for (const SectionRef &Section : Obj->sections()) { StringRef Name; - if (Expected<StringRef> NameOrErr = Section.getName()) - Name = *NameOrErr; - else - consumeError(NameOrErr.takeError()); + consumeError(Section.getName().moveInto(Name)); Name = Name.substr(Name.find_first_not_of("._")); if (Name == "gnu_debuglink") { diff --git a/llvm/lib/Object/ObjectFile.cpp b/llvm/lib/Object/ObjectFile.cpp index 5c894439ff67..6fd02f3b9592 100644 --- a/llvm/lib/Object/ObjectFile.cpp +++ b/llvm/lib/Object/ObjectFile.cpp @@ -55,14 +55,15 @@ bool SectionRef::containsSymbol(SymbolRef S) const { } Expected<uint64_t> ObjectFile::getSymbolValue(DataRefImpl Ref) const { - if (Expected<uint32_t> FlagsOrErr = getSymbolFlags(Ref)) { - if (*FlagsOrErr & SymbolRef::SF_Undefined) - return 0; - if (*FlagsOrErr & SymbolRef::SF_Common) - return getCommonSymbolSize(Ref); - } else + uint32_t Flags; + if (Error E = getSymbolFlags(Ref).moveInto(Flags)) // TODO: Test this error. - return FlagsOrErr.takeError(); + return std::move(E); + + if (Flags & SymbolRef::SF_Undefined) + return 0; + if (Flags & SymbolRef::SF_Common) + return getCommonSymbolSize(Ref); return getSymbolValueImpl(Ref); } diff --git a/llvm/lib/XRay/InstrumentationMap.cpp b/llvm/lib/XRay/InstrumentationMap.cpp index 089591c4a7df..c60efa465bb6 100644 --- a/llvm/lib/XRay/InstrumentationMap.cpp +++ b/llvm/lib/XRay/InstrumentationMap.cpp @@ -86,10 +86,8 @@ loadObj(StringRef Filename, object::OwningBinary<object::ObjectFile> &ObjFile, "Failed to find XRay instrumentation map.", std::make_error_code(std::errc::executable_format_error)); - if (Expected<StringRef> E = I->getContents()) - Contents = *E; - else - return E.takeError(); + if (Error E = I->getContents().moveInto(Contents)) + return E; RelocMap Relocs; if (ObjFile.getBinary()->isELF()) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits