[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
Tue Oct 31 09:38:07 PDT 2017
thakis updated this revision to Diff 120997.
thakis added a comment.
Now with better test. I'm going to land this; happy to address post-commit review comments of course.
https://reviews.llvm.org/D39437
Files:
lib/LTO/LTOModule.cpp
test/tools/lto/no-bitcode.s
Index: test/tools/lto/no-bitcode.s
===================================================================
--- test/tools/lto/no-bitcode.s
+++ test/tools/lto/no-bitcode.s
@@ -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
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,7 +77,11 @@
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 @@
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 @@
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.120997.patch
Type: text/x-patch
Size: 2168 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171031/7683cf34/attachment.bin>
More information about the llvm-commits
mailing list