[lld] r264973 - Convert readBinary to llvm::Error. NFC

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 30 16:58:24 PDT 2016


Author: pete
Date: Wed Mar 30 18:58:24 2016
New Revision: 264973

URL: http://llvm.org/viewvc/llvm-project?rev=264973&view=rev
Log:
Convert readBinary to llvm::Error.  NFC

Modified:
    lld/trunk/lib/ReaderWriter/MachO/File.h
    lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h
    lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp
    lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp
    lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp

Modified: lld/trunk/lib/ReaderWriter/MachO/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/File.h?rev=264973&r1=264972&r2=264973&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/File.h (original)
+++ lld/trunk/lib/ReaderWriter/MachO/File.h Wed Mar 30 18:58:24 2016
@@ -228,8 +228,8 @@ protected:
   std::error_code doParse() override {
     // Convert binary file to normalized mach-o.
     auto normFile = normalized::readBinary(_mb, _ctx->arch());
-    if (std::error_code ec = normFile.getError())
-      return ec;
+    if (auto ec = normFile.takeError())
+      return llvm::errorToErrorCode(std::move(ec));
     // Convert normalized mach-o to atoms.
     if (auto ec = normalized::normalizedObjectToAtoms(this, **normFile, false))
       return llvm::errorToErrorCode(std::move(ec));
@@ -317,8 +317,8 @@ public:
   std::error_code doParse() override {
     // Convert binary file to normalized mach-o.
     auto normFile = normalized::readBinary(_mb, _ctx->arch());
-    if (std::error_code ec = normFile.getError())
-      return ec;
+    if (auto ec = normFile.takeError())
+      return llvm::errorToErrorCode(std::move(ec));
     // Convert normalized mach-o to atoms.
     if (auto ec = normalized::normalizedDylibToAtoms(this, **normFile, false))
       return llvm::errorToErrorCode(std::move(ec));

Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h?rev=264973&r1=264972&r2=264973&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h Wed Mar 30 18:58:24 2016
@@ -289,7 +289,7 @@ bool sliceFromFatFile(MemoryBufferRef mb
                       uint32_t &offset, uint32_t &size);
 
 /// Reads a mach-o file and produces an in-memory normalized view.
-ErrorOr<std::unique_ptr<NormalizedFile>>
+llvm::Expected<std::unique_ptr<NormalizedFile>>
 readBinary(std::unique_ptr<MemoryBuffer> &mb,
            const MachOLinkingContext::Arch arch);
 

Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp?rev=264973&r1=264972&r2=264973&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp Wed Mar 30 18:58:24 2016
@@ -199,7 +199,7 @@ bool sliceFromFatFile(MemoryBufferRef mb
 }
 
 /// Reads a mach-o file and produces an in-memory normalized view.
-ErrorOr<std::unique_ptr<NormalizedFile>>
+llvm::Expected<std::unique_ptr<NormalizedFile>>
 readBinary(std::unique_ptr<MemoryBuffer> &mb,
            const MachOLinkingContext::Arch arch) {
   // Make empty NormalizedFile.
@@ -220,7 +220,7 @@ readBinary(std::unique_ptr<MemoryBuffer>
   // Determine endianness and pointer size for mach-o file.
   bool is64, isBig;
   if (!isMachOHeader(mh, is64, isBig))
-    return make_error_code(llvm::errc::executable_format_error);
+    return llvm::make_error<GenericError>("File is not a mach-o");
 
   // Endian swap header, if needed.
   mach_header headerCopy;
@@ -237,12 +237,13 @@ readBinary(std::unique_ptr<MemoryBuffer>
       start + (is64 ? sizeof(mach_header_64) : sizeof(mach_header));
   StringRef lcRange(lcStart, smh->sizeofcmds);
   if (lcRange.end() > (start + objSize))
-    return make_error_code(llvm::errc::executable_format_error);
+    return llvm::make_error<GenericError>("Load commands exceed file size");
 
   // Get architecture from mach_header.
   f->arch = MachOLinkingContext::archFromCpuType(smh->cputype, smh->cpusubtype);
   if (f->arch != arch) {
-    return make_dynamic_error_code(Twine("file is wrong architecture. Expected "
+    return llvm::make_error<GenericError>(
+                                  Twine("file is wrong architecture. Expected "
                                   "(" + MachOLinkingContext::nameFromArch(arch)
                                   + ") found ("
                                   + MachOLinkingContext::nameFromArch(f->arch)
@@ -268,7 +269,7 @@ readBinary(std::unique_ptr<MemoryBuffer>
     return false;
   });
   if (ec)
-    return ec;
+    return llvm::errorCodeToError(ec);
 
   // Walk load commands looking for segments/sections and the symbol table.
   const data_in_code_entry *dataInCode = nullptr;
@@ -484,7 +485,7 @@ readBinary(std::unique_ptr<MemoryBuffer>
     return false;
   });
   if (ec)
-    return ec;
+    return llvm::errorCodeToError(ec);
 
   if (dataInCode) {
     // Convert on-disk data_in_code_entry array to DataInCode vector.

Modified: lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp?rev=264973&r1=264972&r2=264973&view=diff
==============================================================================
--- lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp (original)
+++ lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp Wed Mar 30 18:58:24 2016
@@ -22,7 +22,7 @@ static std::unique_ptr<NormalizedFile>
 fromBinary(const uint8_t bytes[], unsigned length, StringRef archStr) {
   StringRef sr((const char*)bytes, length);
   std::unique_ptr<MemoryBuffer> mb(MemoryBuffer::getMemBuffer(sr, "", false));
-  ErrorOr<std::unique_ptr<NormalizedFile>> r =
+  llvm::Expected<std::unique_ptr<NormalizedFile>> r =
       lld::mach_o::normalized::readBinary(
           mb, lld::MachOLinkingContext::archFromName(archStr));
   EXPECT_FALSE(!r);

Modified: lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp?rev=264973&r1=264972&r2=264973&view=diff
==============================================================================
--- lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp (original)
+++ lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp Wed Mar 30 18:58:24 2016
@@ -35,7 +35,7 @@ static void fromBinary(StringRef path, s
   EXPECT_FALSE(ec);
   mb = std::move(mbOrErr.get());
 
-  ErrorOr<std::unique_ptr<NormalizedFile>> r =
+  llvm::Expected<std::unique_ptr<NormalizedFile>> r =
       lld::mach_o::normalized::readBinary(
           mb, lld::MachOLinkingContext::archFromName(archStr));
   EXPECT_FALSE(!r);




More information about the llvm-commits mailing list