[llvm] r317010 - LTOModule::isBitcodeFile() shouldn't assert when returning false.
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 31 09:39:47 PDT 2017
Author: nico
Date: Tue Oct 31 09:39:47 2017
New Revision: 317010
URL: http://llvm.org/viewvc/llvm-project?rev=317010&view=rev
Log:
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
Added:
llvm/trunk/test/tools/lto/no-bitcode.s
Modified:
llvm/trunk/lib/LTO/LTOModule.cpp
Modified: llvm/trunk/lib/LTO/LTOModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOModule.cpp?rev=317010&r1=317009&r2=317010&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOModule.cpp (original)
+++ llvm/trunk/lib/LTO/LTOModule.cpp Tue Oct 31 09:39:47 2017
@@ -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
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(Memor
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(Memor
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));
Added: llvm/trunk/test/tools/lto/no-bitcode.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/lto/no-bitcode.s?rev=317010&view=auto
==============================================================================
--- llvm/trunk/test/tools/lto/no-bitcode.s (added)
+++ llvm/trunk/test/tools/lto/no-bitcode.s Tue Oct 31 09:39:47 2017
@@ -0,0 +1,4 @@
+; libLTO.dylib shouldn't assert on invalid inputs.
+; RUN: llvm-mc -triple=arm64-apple-ios7.0.0 -filetype=obj -o %t.o
+; RUN: llvm-ar r %t.a %t.o
+; RUN: %ld64 -lto_library %llvmshlibdir/libLTO.dylib -arch x86_64 -dylib -mllvm -O0 -o %t.dylib %t.a
More information about the llvm-commits
mailing list