diff --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp --- a/llvm/lib/Object/ArchiveWriter.cpp +++ b/llvm/lib/Object/ArchiveWriter.cpp @@ -362,11 +362,8 @@ if (identify_magic(Buf.getBuffer()) == file_magic::bitcode) { auto ObjOrErr = object::SymbolicFile::createSymbolicFile( Buf, file_magic::bitcode, &Context); - if (!ObjOrErr) { - // FIXME: check only for "not an object file" errors. - consumeError(ObjOrErr.takeError()); - return Ret; - } + if (auto E = ObjOrErr.takeError()) + return std::move(E); Obj = std::move(*ObjOrErr); } else { auto ObjOrErr = object::SymbolicFile::createSymbolicFile(Buf); diff --git a/llvm/test/tools/llvm-ar/invalid-bitcode.test b/llvm/test/tools/llvm-ar/invalid-bitcode.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-ar/invalid-bitcode.test @@ -0,0 +1,2 @@ +; RUN: printf "\xDE\xC0\x17\x0B" > %t.o +; RUN: not llvm-ar cr %t.a %t.o 2>&1 | grep "Invalid bitcode wrapper header"