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
This commit is contained in:
Rui Ueyama 2016-07-15 01:38:54 +00:00
parent 615b85d9b4
commit aa2db88984
3 changed files with 7 additions and 7 deletions

View File

@ -150,9 +150,10 @@ void LinkerDriver::addFile(StringRef Path) {
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

View File

@ -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) {

View File

@ -1233,10 +1233,10 @@ template <class ELFT> void Writer<ELFT>::openFile() {
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.