From: Fangrui Song Date: Thu, 16 May 2019 13:24:04 +0000 (+0000) Subject: Recommit [Object] Change object::SectionRef::getContents() to return Expected X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b6c6b38192cc34367f86bb3ff150157368b19dfe;p=clang Recommit [Object] Change object::SectionRef::getContents() to return Expected r360876 didn't fix 2 call sites in clang. Expected> may be better but use Expected for now. Follow-up of D61781. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360892 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/ObjectFilePCHContainerOperations.cpp b/lib/CodeGen/ObjectFilePCHContainerOperations.cpp index db53959ea0..db6e73f409 100644 --- a/lib/CodeGen/ObjectFilePCHContainerOperations.cpp +++ b/lib/CodeGen/ObjectFilePCHContainerOperations.cpp @@ -337,8 +337,14 @@ ObjectFilePCHContainerReader::ExtractPCH(llvm::MemoryBufferRef Buffer) const { StringRef Name; Section.getName(Name); if ((!IsCOFF && Name == "__clangast") || (IsCOFF && Name == "clangast")) { - Section.getContents(PCH); - return PCH; + if (Expected E = Section.getContents()) + return *E; + else { + handleAllErrors(E.takeError(), [&](const llvm::ErrorInfoBase &EIB) { + EIB.log(llvm::errs()); + }); + return ""; + } } } } diff --git a/tools/clang-offload-bundler/ClangOffloadBundler.cpp b/tools/clang-offload-bundler/ClangOffloadBundler.cpp index 4e7cdd6c91..0c628963a2 100644 --- a/tools/clang-offload-bundler/ClangOffloadBundler.cpp +++ b/tools/clang-offload-bundler/ClangOffloadBundler.cpp @@ -462,13 +462,16 @@ public: // TODO: Instead of copying the input file as is, deactivate the section // that is no longer needed. - StringRef Content; - CurrentSection->getContents(Content); + Expected Content = CurrentSection->getContents(); + if (!Content) { + consumeError(Content.takeError()); + return; + } - if (Content.size() < 2) + if (Content->size() < 2) OS.write(Input.getBufferStart(), Input.getBufferSize()); else - OS.write(Content.data(), Content.size()); + OS.write(Content->data(), Content->size()); } void WriteHeader(raw_fd_ostream &OS,