summaryrefslogtreecommitdiffstats
path: root/llvm/lib/LTO/LTOModule.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2018-01-23 19:03:13 +0000
committerNico Weber <nicolasweber@gmx.de>2018-01-23 19:03:13 +0000
commit1c7c45688c857427738e62b3bf573c5bb2bcee8b (patch)
tree7d9744bf6c9b189606de691d766ed9bf40c44c27 /llvm/lib/LTO/LTOModule.cpp
parent2f97aab6eae5b3afcfd614433633ed1e47166650 (diff)
downloadbcm5719-llvm-1c7c45688c857427738e62b3bf573c5bb2bcee8b.tar.gz
bcm5719-llvm-1c7c45688c857427738e62b3bf573c5bb2bcee8b.zip
Introduce errorToBool() helper and use it.
errorToBool() converts an Error to a bool and puts the Error in a checked state. No behavior change. https://reviews.llvm.org/D42422 llvm-svn: 323238
Diffstat (limited to 'llvm/lib/LTO/LTOModule.cpp')
-rw-r--r--llvm/lib/LTO/LTOModule.cpp20
1 files changed, 4 insertions, 16 deletions
diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp
index 626d2f5dc81..f7fe85e5085 100644
--- a/llvm/lib/LTO/LTOModule.cpp
+++ b/llvm/lib/LTO/LTOModule.cpp
@@ -57,11 +57,7 @@ LTOModule::~LTOModule() {}
bool LTOModule::isBitcodeFile(const void *Mem, size_t Length) {
Expected<MemoryBufferRef> BCData = IRObjectFile::findBitcodeInMemBuffer(
MemoryBufferRef(StringRef((const char *)Mem, Length), "<mem>"));
- if (!BCData) {
- consumeError(BCData.takeError());
- return false;
- }
- return true;
+ return !errorToBool(BCData.takeError());
}
bool LTOModule::isBitcodeFile(StringRef Path) {
@@ -72,11 +68,7 @@ bool LTOModule::isBitcodeFile(StringRef Path) {
Expected<MemoryBufferRef> BCData = IRObjectFile::findBitcodeInMemBuffer(
BufferOrErr.get()->getMemBufferRef());
- if (!BCData) {
- consumeError(BCData.takeError());
- return false;
- }
- return true;
+ return !errorToBool(BCData.takeError());
}
bool LTOModule::isThinLTO() {
@@ -92,10 +84,8 @@ bool LTOModule::isBitcodeForTarget(MemoryBuffer *Buffer,
StringRef TriplePrefix) {
Expected<MemoryBufferRef> BCOrErr =
IRObjectFile::findBitcodeInMemBuffer(Buffer->getMemBufferRef());
- if (!BCOrErr) {
- consumeError(BCOrErr.takeError());
+ if (errorToBool(BCOrErr.takeError()))
return false;
- }
LLVMContext Context;
ErrorOr<std::string> TripleOrErr =
expectedToErrorOrAndEmitErrors(Context, getBitcodeTargetTriple(*BCOrErr));
@@ -107,10 +97,8 @@ bool LTOModule::isBitcodeForTarget(MemoryBuffer *Buffer,
std::string LTOModule::getProducerString(MemoryBuffer *Buffer) {
Expected<MemoryBufferRef> BCOrErr =
IRObjectFile::findBitcodeInMemBuffer(Buffer->getMemBufferRef());
- if (!BCOrErr) {
- consumeError(BCOrErr.takeError());
+ if (errorToBool(BCOrErr.takeError()))
return "";
- }
LLVMContext Context;
ErrorOr<std::string> ProducerOrErr = expectedToErrorOrAndEmitErrors(
Context, getBitcodeProducerString(*BCOrErr));
OpenPOWER on IntegriCloud