[lld] r263362 - Do not return a bool value from error().
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 12 20:25:42 PST 2016
Author: ruiu
Date: Sat Mar 12 22:25:41 2016
New Revision: 263362
URL: http://llvm.org/viewvc/llvm-project?rev=263362&view=rev
Log:
Do not return a bool value from error().
error returned true if there was an error. This allows us to replace
the code like this
if (EC) {
error(EC, "something failed");
return;
}
with
if (error(EC, "something failed"))
return;
I thought that that was a good idea, but it turned out that we only
have two places to use this pattern. So this patch removes that feature.
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Error.cpp
lld/trunk/ELF/Error.h
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=263362&r1=263361&r2=263362&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Sat Mar 12 22:25:41 2016
@@ -92,8 +92,10 @@ void LinkerDriver::addFile(StringRef Pat
using namespace llvm::sys::fs;
log(Path);
auto MBOrErr = MemoryBuffer::getFile(Path);
- if (error(MBOrErr, "cannot open " + Path))
+ if (!MBOrErr) {
+ error(MBOrErr, "cannot open " + Path);
return;
+ }
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=263362&r1=263361&r2=263362&view=diff
==============================================================================
--- lld/trunk/ELF/Error.cpp (original)
+++ lld/trunk/ELF/Error.cpp Sat Mar 12 22:25:41 2016
@@ -31,18 +31,14 @@ void error(const Twine &Msg) {
HasError = true;
}
-bool error(std::error_code EC, const Twine &Prefix) {
- if (!EC)
- return false;
- error(Prefix + ": " + EC.message());
- return true;
+void error(std::error_code EC, const Twine &Prefix) {
+ if (EC)
+ error(Prefix + ": " + EC.message());
}
-bool error(std::error_code EC) {
- if (!EC)
- return false;
- error(EC.message());
- return true;
+void error(std::error_code EC) {
+ if (EC)
+ error(EC.message());
}
void fatal(const Twine &Msg) {
Modified: lld/trunk/ELF/Error.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Error.h?rev=263362&r1=263361&r2=263362&view=diff
==============================================================================
--- lld/trunk/ELF/Error.h (original)
+++ lld/trunk/ELF/Error.h Sat Mar 12 22:25:41 2016
@@ -22,14 +22,14 @@ void log(const Twine &Msg);
void warning(const Twine &Msg);
void error(const Twine &Msg);
-bool error(std::error_code EC, const Twine &Prefix);
-bool error(std::error_code EC);
+void error(std::error_code EC, const Twine &Prefix);
+void error(std::error_code EC);
-template <typename T> bool error(const ErrorOr<T> &V, const Twine &Prefix) {
+template <typename T> void error(const ErrorOr<T> &V, const Twine &Prefix) {
return error(V.getError(), Prefix);
}
-template <typename T> bool error(const ErrorOr<T> &V) {
+template <typename T> void error(const ErrorOr<T> &V) {
return error(V.getError());
}
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=263362&r1=263361&r2=263362&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Sat Mar 12 22:25:41 2016
@@ -1534,8 +1534,10 @@ template <class ELFT> bool Writer<ELFT>:
ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
FileOutputBuffer::create(Config->OutputFile, FileSize,
FileOutputBuffer::F_executable);
- if (error(BufferOrErr, "failed to open " + Config->OutputFile))
+ if (!BufferOrErr) {
+ error(BufferOrErr, "failed to open " + Config->OutputFile);
return false;
+ }
Buffer = std::move(*BufferOrErr);
return true;
}
More information about the llvm-commits
mailing list