[lld] r275517 - ELF: Make error() to always set HasError.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 14 18:38:54 PDT 2016


Author: ruiu
Date: Thu Jul 14 20:38:54 2016
New Revision: 275517

URL: http://llvm.org/viewvc/llvm-project?rev=275517&view=rev
Log:
ELF: Make error() to always set HasError.

Previously, it checked for the EC parameter and set HasError
only when there was an error. But in most places we called
error only when error had occurred, so this behavior was confusing.

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/Error.cpp
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=275517&r1=275516&r2=275517&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu Jul 14 20:38:54 2016
@@ -150,9 +150,10 @@ void LinkerDriver::addFile(StringRef Pat
 
 Optional<MemoryBufferRef> LinkerDriver::readFile(StringRef Path) {
   auto MBOrErr = MemoryBuffer::getFile(Path);
-  error(MBOrErr, "cannot open " + Path);
-  if (HasError)
+  if (auto EC = MBOrErr.getError()) {
+    error(EC, "cannot open " + Path);
     return None;
+  }
   std::unique_ptr<MemoryBuffer> &MB = *MBOrErr;
   MemoryBufferRef MBRef = MB->getMemBufferRef();
   OwningMBs.push_back(std::move(MB)); // take MB ownership

Modified: lld/trunk/ELF/Error.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Error.cpp?rev=275517&r1=275516&r2=275517&view=diff
==============================================================================
--- lld/trunk/ELF/Error.cpp (original)
+++ lld/trunk/ELF/Error.cpp Thu Jul 14 20:38:54 2016
@@ -40,8 +40,7 @@ void error(const Twine &Msg) {
 }
 
 void error(std::error_code EC, const Twine &Prefix) {
-  if (EC)
-    error(Prefix + ": " + EC.message());
+  error(Prefix + ": " + EC.message());
 }
 
 void fatal(const Twine &Msg) {

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=275517&r1=275516&r2=275517&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Jul 14 20:38:54 2016
@@ -1233,10 +1233,10 @@ template <class ELFT> void Writer<ELFT>:
   ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
       FileOutputBuffer::create(Config->OutputFile, FileSize,
                                FileOutputBuffer::F_executable);
-  if (BufferOrErr)
-    Buffer = std::move(*BufferOrErr);
+  if (auto EC = BufferOrErr.getError())
+    error(EC, "failed to open " + Config->OutputFile);
   else
-    error(BufferOrErr, "failed to open " + Config->OutputFile);
+    Buffer = std::move(*BufferOrErr);
 }
 
 // Write section contents to a mmap'ed file.




More information about the llvm-commits mailing list