Index: clang/lib/CodeGen/BackendUtil.cpp =================================================================== --- clang/lib/CodeGen/BackendUtil.cpp +++ clang/lib/CodeGen/BackendUtil.cpp @@ -1657,16 +1657,17 @@ // 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> IndexOrErr = - llvm::getModuleSummaryIndexForFile(CGOpts.ThinLTOIndexFile, - /*IgnoreEmptyThinLTOIndexFile*/true); - if (!IndexOrErr) { - logAllUnhandledErrors(IndexOrErr.takeError(), errs(), + std::unique_ptr 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 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). Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp =================================================================== --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -179,10 +179,8 @@ while (true) { BitstreamEntry Entry; - if (Expected 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 @@ return ""; BitstreamEntry Entry; - if (Expected 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 @@ // need to understand them all. while (true) { BitstreamEntry Entry; - if (Expected 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: Index: llvm/lib/DebugInfo/Symbolize/Symbolize.cpp =================================================================== --- llvm/lib/DebugInfo/Symbolize/Symbolize.cpp +++ llvm/lib/DebugInfo/Symbolize/Symbolize.cpp @@ -280,10 +280,7 @@ return false; for (const SectionRef &Section : Obj->sections()) { StringRef Name; - if (Expected 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") { Index: llvm/lib/Object/ObjectFile.cpp =================================================================== --- llvm/lib/Object/ObjectFile.cpp +++ llvm/lib/Object/ObjectFile.cpp @@ -55,14 +55,15 @@ } Expected ObjectFile::getSymbolValue(DataRefImpl Ref) const { - if (Expected 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); } Index: llvm/lib/XRay/InstrumentationMap.cpp =================================================================== --- llvm/lib/XRay/InstrumentationMap.cpp +++ llvm/lib/XRay/InstrumentationMap.cpp @@ -86,10 +86,8 @@ "Failed to find XRay instrumentation map.", std::make_error_code(std::errc::executable_format_error)); - if (Expected E = I->getContents()) - Contents = *E; - else - return E.takeError(); + if (Error E = I->getContents().moveInto(Contents)) + return E; RelocMap Relocs; if (ObjFile.getBinary()->isELF()) {