]> granicus.if.org Git - clang/commitdiff
Recommit [Object] Change object::SectionRef::getContents() to return Expected<StringRef>
authorFangrui Song <maskray@google.com>
Thu, 16 May 2019 13:24:04 +0000 (13:24 +0000)
committerFangrui Song <maskray@google.com>
Thu, 16 May 2019 13:24:04 +0000 (13:24 +0000)
r360876 didn't fix 2 call sites in clang.

Expected<ArrayRef<uint8_t>> may be better but use Expected<StringRef> for now.

Follow-up of D61781.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360892 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/ObjectFilePCHContainerOperations.cpp
tools/clang-offload-bundler/ClangOffloadBundler.cpp

index db53959ea0bdcd70f840213c5fabc90f01c9ac0b..db6e73f409776cb85a36259b941f37c3d787039f 100644 (file)
@@ -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<StringRef> E = Section.getContents())
+          return *E;
+        else {
+          handleAllErrors(E.takeError(), [&](const llvm::ErrorInfoBase &EIB) {
+            EIB.log(llvm::errs());
+          });
+          return "";
+        }
       }
     }
   }
index 4e7cdd6c9133a5b5a358fa254703248d6e15b48b..0c628963a29180fc843c12353994a786051dad17 100644 (file)
@@ -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<StringRef> 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,