diff --git a/clang-tools-extra/clangd/index/Serialization.cpp b/clang-tools-extra/clangd/index/Serialization.cpp --- a/clang-tools-extra/clangd/index/Serialization.cpp +++ b/clang-tools-extra/clangd/index/Serialization.cpp @@ -192,7 +192,7 @@ } if (llvm::zlib::isAvailable()) { llvm::SmallString<1> Compressed; - llvm::cantFail(llvm::zlib::compress(RawTable, Compressed)); + llvm::zlib::compress(RawTable, Compressed); write32(RawTable.size(), OS); OS << Compressed; } else { diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -2007,15 +2007,11 @@ // consumers will not want its contents. SmallString<0> CompressedBuffer; if (llvm::zlib::isAvailable()) { - llvm::Error E = llvm::zlib::compress(Blob.drop_back(1), CompressedBuffer); - if (!E) { - RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED, - Blob.size() - 1}; - Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record, - CompressedBuffer); - return; - } - llvm::consumeError(std::move(E)); + llvm::zlib::compress(Blob.drop_back(1), CompressedBuffer); + RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED, Blob.size() - 1}; + Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record, + CompressedBuffer); + return; } RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB}; diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h --- a/llvm/include/llvm/ProfileData/SampleProf.h +++ b/llvm/include/llvm/ProfileData/SampleProf.h @@ -55,7 +55,6 @@ not_implemented, counter_overflow, ostream_seek_unsupported, - compress_failed, uncompress_failed, zlib_unavailable, hash_mismatch diff --git a/llvm/include/llvm/Support/Compression.h b/llvm/include/llvm/Support/Compression.h --- a/llvm/include/llvm/Support/Compression.h +++ b/llvm/include/llvm/Support/Compression.h @@ -29,8 +29,8 @@ bool isAvailable(); -Error compress(StringRef InputBuffer, SmallVectorImpl &CompressedBuffer, - int Level = DefaultCompression); +void compress(StringRef InputBuffer, SmallVectorImpl &CompressedBuffer, + int Level = DefaultCompression); Error uncompress(StringRef InputBuffer, char *UncompressedBuffer, size_t &UncompressedSize); diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -864,13 +864,8 @@ Asm.writeSectionData(VecOS, &Section, Layout); SmallVector CompressedContents; - if (Error E = zlib::compress( - StringRef(UncompressedData.data(), UncompressedData.size()), - CompressedContents)) { - consumeError(std::move(E)); - W.OS << UncompressedData; - return; - } + zlib::compress(StringRef(UncompressedData.data(), UncompressedData.size()), + CompressedContents); bool ZlibStyle = MAI->compressDebugSections() == DebugCompressionType::Z; if (!maybeWriteCompression(UncompressedData.size(), CompressedContents, diff --git a/llvm/lib/ObjCopy/ELF/ELFObject.cpp b/llvm/lib/ObjCopy/ELF/ELFObject.cpp --- a/llvm/lib/ObjCopy/ELF/ELFObject.cpp +++ b/llvm/lib/ObjCopy/ELF/ELFObject.cpp @@ -570,14 +570,9 @@ DecompressedSize(Sec.OriginalData.size()), DecompressedAlign(Sec.Align) { ErrorAsOutParameter EAO(&OutErr); - if (Error Err = zlib::compress( - StringRef(reinterpret_cast(OriginalData.data()), - OriginalData.size()), - CompressedData)) { - OutErr = createStringError(llvm::errc::invalid_argument, - "'" + Name + "': " + toString(std::move(Err))); - return; - } + zlib::compress(StringRef(reinterpret_cast(OriginalData.data()), + OriginalData.size()), + CompressedData); size_t ChdrSize; if (CompressionType == DebugCompressionType::GNU) { diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp --- a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp +++ b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp @@ -49,12 +49,8 @@ SmallString<128> CompressedStr; bool doCompression = Compress && zlib::isAvailable() && DoInstrProfNameCompression; - if (doCompression) { - auto E = - zlib::compress(FilenamesStr, CompressedStr, zlib::BestSizeCompression); - if (E) - report_bad_alloc_error("Failed to zlib compress coverage data"); - } + if (doCompression) + zlib::compress(FilenamesStr, CompressedStr, zlib::BestSizeCompression); // ::= // diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp --- a/llvm/lib/ProfileData/InstrProf.cpp +++ b/llvm/lib/ProfileData/InstrProf.cpp @@ -467,12 +467,8 @@ } SmallString<128> CompressedNameStrings; - Error E = zlib::compress(StringRef(UncompressedNameStrings), - CompressedNameStrings, zlib::BestSizeCompression); - if (E) { - consumeError(std::move(E)); - return make_error(instrprof_error::compress_failed); - } + zlib::compress(StringRef(UncompressedNameStrings), CompressedNameStrings, + zlib::BestSizeCompression); return WriteStringToResult(CompressedNameStrings.size(), CompressedNameStrings); diff --git a/llvm/lib/ProfileData/SampleProf.cpp b/llvm/lib/ProfileData/SampleProf.cpp --- a/llvm/lib/ProfileData/SampleProf.cpp +++ b/llvm/lib/ProfileData/SampleProf.cpp @@ -85,8 +85,6 @@ return "Counter overflow"; case sampleprof_error::ostream_seek_unsupported: return "Ostream does not support seek"; - case sampleprof_error::compress_failed: - return "Compress failure"; case sampleprof_error::uncompress_failed: return "Uncompress failure"; case sampleprof_error::zlib_unavailable: diff --git a/llvm/lib/ProfileData/SampleProfWriter.cpp b/llvm/lib/ProfileData/SampleProfWriter.cpp --- a/llvm/lib/ProfileData/SampleProfWriter.cpp +++ b/llvm/lib/ProfileData/SampleProfWriter.cpp @@ -86,10 +86,8 @@ return sampleprof_error::success; auto &OS = *OutputStream; SmallString<128> CompressedStrings; - llvm::Error E = zlib::compress(UncompressedStrings, CompressedStrings, - zlib::BestSizeCompression); - if (E) - return sampleprof_error::compress_failed; + zlib::compress(UncompressedStrings, CompressedStrings, + zlib::BestSizeCompression); encodeULEB128(UncompressedStrings.size(), OS); encodeULEB128(CompressedStrings.size(), OS); OS << CompressedStrings.str(); diff --git a/llvm/lib/Support/Compression.cpp b/llvm/lib/Support/Compression.cpp --- a/llvm/lib/Support/Compression.cpp +++ b/llvm/lib/Support/Compression.cpp @@ -46,18 +46,20 @@ bool zlib::isAvailable() { return true; } -Error zlib::compress(StringRef InputBuffer, - SmallVectorImpl &CompressedBuffer, int Level) { +void zlib::compress(StringRef InputBuffer, + SmallVectorImpl &CompressedBuffer, int Level) { unsigned long CompressedSize = ::compressBound(InputBuffer.size()); CompressedBuffer.resize_for_overwrite(CompressedSize); int Res = ::compress2((Bytef *)CompressedBuffer.data(), &CompressedSize, (const Bytef *)InputBuffer.data(), InputBuffer.size(), Level); + if (Res == Z_MEM_ERROR) + report_bad_alloc_error("Allocation failed"); + assert(Res == Z_OK); // Tell MemorySanitizer that zlib output buffer is fully initialized. // This avoids a false report when running LLVM with uninstrumented ZLib. __msan_unpoison(CompressedBuffer.data(), CompressedSize); CompressedBuffer.truncate(CompressedSize); - return Res ? createError(convertZlibCodeToString(Res)) : Error::success(); } Error zlib::uncompress(StringRef InputBuffer, char *UncompressedBuffer, @@ -87,8 +89,8 @@ #else bool zlib::isAvailable() { return false; } -Error zlib::compress(StringRef InputBuffer, - SmallVectorImpl &CompressedBuffer, int Level) { +void zlib::compress(StringRef InputBuffer, + SmallVectorImpl &CompressedBuffer, int Level) { llvm_unreachable("zlib::compress is unavailable"); } Error zlib::uncompress(StringRef InputBuffer, char *UncompressedBuffer, diff --git a/llvm/unittests/Support/CompressionTest.cpp b/llvm/unittests/Support/CompressionTest.cpp --- a/llvm/unittests/Support/CompressionTest.cpp +++ b/llvm/unittests/Support/CompressionTest.cpp @@ -27,13 +27,10 @@ SmallString<32> Compressed; SmallString<32> Uncompressed; - Error E = zlib::compress(Input, Compressed, Level); - EXPECT_FALSE(E); - consumeError(std::move(E)); + zlib::compress(Input, Compressed, Level); // Check that uncompressed buffer is the same as original. - E = zlib::uncompress(Compressed, Uncompressed, Input.size()); - EXPECT_FALSE(E); + Error E = zlib::uncompress(Compressed, Uncompressed, Input.size()); consumeError(std::move(E)); EXPECT_EQ(Input, Uncompressed);