From aa2db889847114c6348c113e6215560ff2346cc2 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 15 Jul 2016 01:38:54 +0000 Subject: [PATCH] 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. llvm-svn: 275517 --- lld/ELF/Driver.cpp | 5 +++-- lld/ELF/Error.cpp | 3 +-- lld/ELF/Writer.cpp | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index a967a7f..ea1f58f 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -150,9 +150,10 @@ void LinkerDriver::addFile(StringRef Path) { Optional 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 &MB = *MBOrErr; MemoryBufferRef MBRef = MB->getMemBufferRef(); OwningMBs.push_back(std::move(MB)); // take MB ownership diff --git a/lld/ELF/Error.cpp b/lld/ELF/Error.cpp index e1042f0..64570cf 100644 --- a/lld/ELF/Error.cpp +++ b/lld/ELF/Error.cpp @@ -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) { diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 214b6d2..7b9d940 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1233,10 +1233,10 @@ template void Writer::openFile() { ErrorOr> 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. -- 2.7.4