[PATCH] D39437: Fix a bunch of assert-on-invalid-bitcode regressions after 315483
Nico Weber via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 30 15:28:22 PDT 2017
thakis created this revision.
Herald added subscribers: kristof.beyls, mehdi_amini, aemerson.
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.
I didn't audit other revisions that converted ErrorOr<> to Expected<>, there are possibly more changes like this needed.
This fixes an assert from libLTO.dylib while linking chrome/iOS.
https://reviews.llvm.org/D39437
Files:
lib/LTO/LTOModule.cpp
Index: lib/LTO/LTOModule.cpp
===================================================================
--- lib/LTO/LTOModule.cpp
+++ lib/LTO/LTOModule.cpp
@@ -62,7 +62,11 @@
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,6 +77,11 @@
Expected<MemoryBufferRef> BCData = IRObjectFile::findBitcodeInMemBuffer(
BufferOrErr.get()->getMemBufferRef());
+ if (!BCData) {
+ consumeError(BCData.takeError());
+ return false;
+ }
+ return true;
return bool(BCData);
}
@@ -89,8 +98,10 @@
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 +113,10 @@
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));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39437.120901.patch
Type: text/x-patch
Size: 1705 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171030/17d892db/attachment.bin>
More information about the llvm-commits
mailing list