diff options
| author | Nico Weber <nicolasweber@gmx.de> | 2017-10-31 16:39:47 +0000 |
|---|---|---|
| committer | Nico Weber <nicolasweber@gmx.de> | 2017-10-31 16:39:47 +0000 |
| commit | 05c988473f508a1c37ab739898ed95b5456c47cf (patch) | |
| tree | fef61bd62f8979b3a734b70f576483b9b2cd8ba4 /llvm/lib/LTO | |
| parent | c212cc88e2b61d197d9a60acbc116c52d3555101 (diff) | |
| download | bcm5719-llvm-05c988473f508a1c37ab739898ed95b5456c47cf.tar.gz bcm5719-llvm-05c988473f508a1c37ab739898ed95b5456c47cf.zip | |
LTOModule::isBitcodeFile() shouldn't assert when returning false.
Fixes a bunch of assert-on-invalid-bitcode regressions after 315483.
Expected<> calls assertIsChecked() in its dtor, and operator bool() only calls
setChecked() if there's no error. So for functions that don't return an error
itself, the Expected<> version needs explicit code to disarm the error that the
ErrorOr<> code didn't need.
https://reviews.llvm.org/D39437
llvm-svn: 317010
Diffstat (limited to 'llvm/lib/LTO')
| -rw-r--r-- | llvm/lib/LTO/LTOModule.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp index 6a0fbb664da..42a5935cab2 100644 --- a/llvm/lib/LTO/LTOModule.cpp +++ b/llvm/lib/LTO/LTOModule.cpp @@ -62,7 +62,11 @@ LTOModule::~LTOModule() {} bool LTOModule::isBitcodeFile(const void *Mem, size_t Length) { Expected<MemoryBufferRef> BCData = IRObjectFile::findBitcodeInMemBuffer( MemoryBufferRef(StringRef((const char *)Mem, Length), "<mem>")); - return bool(BCData); + if (!BCData) { + consumeError(BCData.takeError()); + return false; + } + return true; } bool LTOModule::isBitcodeFile(StringRef Path) { @@ -73,7 +77,11 @@ bool LTOModule::isBitcodeFile(StringRef Path) { Expected<MemoryBufferRef> BCData = IRObjectFile::findBitcodeInMemBuffer( BufferOrErr.get()->getMemBufferRef()); - return bool(BCData); + if (!BCData) { + consumeError(BCData.takeError()); + return false; + } + return true; } bool LTOModule::isThinLTO() { @@ -89,8 +97,10 @@ bool LTOModule::isBitcodeForTarget(MemoryBuffer *Buffer, StringRef TriplePrefix) { Expected<MemoryBufferRef> BCOrErr = IRObjectFile::findBitcodeInMemBuffer(Buffer->getMemBufferRef()); - if (!BCOrErr) + if (!BCOrErr) { + consumeError(BCOrErr.takeError()); return false; + } LLVMContext Context; ErrorOr<std::string> TripleOrErr = expectedToErrorOrAndEmitErrors(Context, getBitcodeTargetTriple(*BCOrErr)); @@ -102,8 +112,10 @@ bool LTOModule::isBitcodeForTarget(MemoryBuffer *Buffer, std::string LTOModule::getProducerString(MemoryBuffer *Buffer) { Expected<MemoryBufferRef> BCOrErr = IRObjectFile::findBitcodeInMemBuffer(Buffer->getMemBufferRef()); - if (!BCOrErr) + if (!BCOrErr) { + consumeError(BCOrErr.takeError()); return ""; + } LLVMContext Context; ErrorOr<std::string> ProducerOrErr = expectedToErrorOrAndEmitErrors( Context, getBitcodeProducerString(*BCOrErr)); |

