[lld] 367997d - [Support] Rename llvm::compression::{zlib,zstd}::uncompress to more appropriate decompress
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 17 12:35:25 PDT 2022
Author: Fangrui Song
Date: 2022-09-17T12:35:17-07:00
New Revision: 367997d0d647db2997311a6eec046559199decd7
URL: https://github.com/llvm/llvm-project/commit/367997d0d647db2997311a6eec046559199decd7
DIFF: https://github.com/llvm/llvm-project/commit/367997d0d647db2997311a6eec046559199decd7.diff
LOG: [Support] Rename llvm::compression::{zlib,zstd}::uncompress to more appropriate decompress
This improves consistency with other places (e.g. llvm::compression::decompress,
llvm::object::Decompressor::decompress, llvm-objcopy).
Note: when zstd::uncompress was added, we noticed that the API `ZSTD_decompress`
is fine while the zlib API `uncompress` is a misnomer.
Added:
Modified:
clang-tools-extra/clangd/index/Serialization.cpp
clang/lib/Serialization/ASTReader.cpp
lld/ELF/InputSection.cpp
llvm/include/llvm/Support/Compression.h
llvm/lib/Object/Decompressor.cpp
llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
llvm/lib/ProfileData/InstrProf.cpp
llvm/lib/ProfileData/SampleProfReader.cpp
llvm/lib/Support/Compression.cpp
llvm/unittests/Support/CompressionTest.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/index/Serialization.cpp b/clang-tools-extra/clangd/index/Serialization.cpp
index 9270c897f88c1..5a00fbf40d8a6 100644
--- a/clang-tools-extra/clangd/index/Serialization.cpp
+++ b/clang-tools-extra/clangd/index/Serialization.cpp
@@ -234,7 +234,7 @@ llvm::Expected<StringTableIn> readStringTable(llvm::StringRef Data) {
return error("Bad stri table: uncompress {0} -> {1} bytes is implausible",
R.rest().size(), UncompressedSize);
- if (llvm::Error E = llvm::compression::zlib::uncompress(
+ if (llvm::Error E = llvm::compression::zlib::decompress(
llvm::arrayRefFromStringRef(R.rest()), UncompressedStorage,
UncompressedSize))
return std::move(E);
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 2196a82604e9c..2716a5971c8f6 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -1459,7 +1459,7 @@ bool ASTReader::ReadSLocEntry(int ID) {
return nullptr;
}
SmallVector<uint8_t, 0> Uncompressed;
- if (llvm::Error E = llvm::compression::zlib::uncompress(
+ if (llvm::Error E = llvm::compression::zlib::decompress(
llvm::arrayRefFromStringRef(Blob), Uncompressed, Record[0])) {
Error("could not decompress embedded file contents: " +
llvm::toString(std::move(E)));
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 8dff884a496d5..75563f8cf3d85 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -116,8 +116,8 @@ static void decompressAux(const InputSectionBase &sec, uint8_t *out,
auto *hdr = reinterpret_cast<const typename ELFT::Chdr *>(sec.rawData.data());
auto compressed = sec.rawData.slice(sizeof(typename ELFT::Chdr));
if (Error e = hdr->ch_type == ELFCOMPRESS_ZLIB
- ? compression::zlib::uncompress(compressed, out, size)
- : compression::zstd::uncompress(compressed, out, size))
+ ? compression::zlib::decompress(compressed, out, size)
+ : compression::zstd::decompress(compressed, out, size))
fatal(toString(&sec) +
": decompress failed: " + llvm::toString(std::move(e)));
}
@@ -1236,8 +1236,8 @@ template <class ELFT> void InputSection::writeTo(uint8_t *buf) {
auto compressed = rawData.slice(sizeof(typename ELFT::Chdr));
size_t size = uncompressedSize;
if (Error e = hdr->ch_type == ELFCOMPRESS_ZLIB
- ? compression::zlib::uncompress(compressed, buf, size)
- : compression::zstd::uncompress(compressed, buf, size))
+ ? compression::zlib::decompress(compressed, buf, size)
+ : compression::zstd::decompress(compressed, buf, size))
fatal(toString(this) +
": decompress failed: " + llvm::toString(std::move(e)));
uint8_t *bufEnd = buf + size;
diff --git a/llvm/include/llvm/Support/Compression.h b/llvm/include/llvm/Support/Compression.h
index 05b7babfac48e..66ad9f8f275fd 100644
--- a/llvm/include/llvm/Support/Compression.h
+++ b/llvm/include/llvm/Support/Compression.h
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
//
-// This file contains basic functions for compression/uncompression.
+// This file contains basic functions for compression/decompression.
//
//===----------------------------------------------------------------------===//
@@ -44,11 +44,10 @@ void compress(ArrayRef<uint8_t> Input,
SmallVectorImpl<uint8_t> &CompressedBuffer,
int Level = DefaultCompression);
-Error uncompress(ArrayRef<uint8_t> Input, uint8_t *UncompressedBuffer,
+Error decompress(ArrayRef<uint8_t> Input, uint8_t *Output,
size_t &UncompressedSize);
-Error uncompress(ArrayRef<uint8_t> Input,
- SmallVectorImpl<uint8_t> &UncompressedBuffer,
+Error decompress(ArrayRef<uint8_t> Input, SmallVectorImpl<uint8_t> &Output,
size_t UncompressedSize);
} // End of namespace zlib
@@ -66,11 +65,10 @@ void compress(ArrayRef<uint8_t> Input,
SmallVectorImpl<uint8_t> &CompressedBuffer,
int Level = DefaultCompression);
-Error uncompress(ArrayRef<uint8_t> Input, uint8_t *UncompressedBuffer,
+Error decompress(ArrayRef<uint8_t> Input, uint8_t *Output,
size_t &UncompressedSize);
-Error uncompress(ArrayRef<uint8_t> Input,
- SmallVectorImpl<uint8_t> &UncompressedBuffer,
+Error decompress(ArrayRef<uint8_t> Input, SmallVectorImpl<uint8_t> &Output,
size_t UncompressedSize);
} // End of namespace zstd
diff --git a/llvm/lib/Object/Decompressor.cpp b/llvm/lib/Object/Decompressor.cpp
index 3842ec92ccfc0..4793124d6f1b4 100644
--- a/llvm/lib/Object/Decompressor.cpp
+++ b/llvm/lib/Object/Decompressor.cpp
@@ -57,6 +57,6 @@ Error Decompressor::consumeCompressedZLibHeader(bool Is64Bit,
Error Decompressor::decompress(MutableArrayRef<uint8_t> Buffer) {
size_t Size = Buffer.size();
- return compression::zlib::uncompress(arrayRefFromStringRef(SectionData),
+ return compression::zlib::decompress(arrayRefFromStringRef(SectionData),
Buffer.data(), Size);
}
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
index 552140a52ad43..4478d8d646d63 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
@@ -129,7 +129,7 @@ Error RawCoverageFilenamesReader::read(CovMapVersion Version) {
// Read compressed filenames.
StringRef CompressedFilenames = Data.substr(0, CompressedLen);
Data = Data.substr(CompressedLen);
- auto Err = compression::zlib::uncompress(
+ auto Err = compression::zlib::decompress(
arrayRefFromStringRef(CompressedFilenames), StorageBuf,
UncompressedLen);
if (Err) {
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index b57380cbf5c1e..9c04bcb8416f5 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -506,7 +506,7 @@ Error readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab) {
if (!llvm::compression::zlib::isAvailable())
return make_error<InstrProfError>(instrprof_error::zlib_unavailable);
- if (Error E = compression::zlib::uncompress(
+ if (Error E = compression::zlib::decompress(
makeArrayRef(P, CompressedSize), UncompressedNameStrings,
UncompressedSize)) {
consumeError(std::move(E));
diff --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp
index 6d1fad4ef1459..6cd6723778319 100644
--- a/llvm/lib/ProfileData/SampleProfReader.cpp
+++ b/llvm/lib/ProfileData/SampleProfReader.cpp
@@ -956,7 +956,7 @@ std::error_code SampleProfileReaderExtBinaryBase::decompressSection(
uint8_t *Buffer = Allocator.Allocate<uint8_t>(DecompressBufSize);
size_t UCSize = DecompressBufSize;
- llvm::Error E = compression::zlib::uncompress(
+ llvm::Error E = compression::zlib::decompress(
makeArrayRef(Data, *CompressSize), Buffer, UCSize);
if (E)
return sampleprof_error::uncompress_failed;
diff --git a/llvm/lib/Support/Compression.cpp b/llvm/lib/Support/Compression.cpp
index 9a04716508431..529e617190dd8 100644
--- a/llvm/lib/Support/Compression.cpp
+++ b/llvm/lib/Support/Compression.cpp
@@ -60,9 +60,9 @@ Error compression::decompress(compression::Format F, ArrayRef<uint8_t> Input,
size_t UncompressedSize) {
switch (F) {
case compression::Format::Zlib:
- return zlib::uncompress(Input, Output, UncompressedSize);
+ return zlib::decompress(Input, Output, UncompressedSize);
case compression::Format::Zstd:
- return zstd::uncompress(Input, Output, UncompressedSize);
+ return zstd::decompress(Input, Output, UncompressedSize);
}
llvm_unreachable("");
}
@@ -109,27 +109,25 @@ void zlib::compress(ArrayRef<uint8_t> Input,
CompressedBuffer.truncate(CompressedSize);
}
-Error zlib::uncompress(ArrayRef<uint8_t> Input, uint8_t *UncompressedBuffer,
+Error zlib::decompress(ArrayRef<uint8_t> Input, uint8_t *Output,
size_t &UncompressedSize) {
- int Res =
- ::uncompress((Bytef *)UncompressedBuffer, (uLongf *)&UncompressedSize,
- (const Bytef *)Input.data(), Input.size());
+ int Res = ::uncompress((Bytef *)Output, (uLongf *)&UncompressedSize,
+ (const Bytef *)Input.data(), Input.size());
// Tell MemorySanitizer that zlib output buffer is fully initialized.
// This avoids a false report when running LLVM with uninstrumented ZLib.
- __msan_unpoison(UncompressedBuffer, UncompressedSize);
+ __msan_unpoison(Output, UncompressedSize);
return Res ? make_error<StringError>(convertZlibCodeToString(Res),
inconvertibleErrorCode())
: Error::success();
}
-Error zlib::uncompress(ArrayRef<uint8_t> Input,
- SmallVectorImpl<uint8_t> &UncompressedBuffer,
+Error zlib::decompress(ArrayRef<uint8_t> Input,
+ SmallVectorImpl<uint8_t> &Output,
size_t UncompressedSize) {
- UncompressedBuffer.resize_for_overwrite(UncompressedSize);
- Error E =
- zlib::uncompress(Input, UncompressedBuffer.data(), UncompressedSize);
- if (UncompressedSize < UncompressedBuffer.size())
- UncompressedBuffer.truncate(UncompressedSize);
+ Output.resize_for_overwrite(UncompressedSize);
+ Error E = zlib::decompress(Input, Output.data(), UncompressedSize);
+ if (UncompressedSize < Output.size())
+ Output.truncate(UncompressedSize);
return E;
}
@@ -139,14 +137,14 @@ void zlib::compress(ArrayRef<uint8_t> Input,
SmallVectorImpl<uint8_t> &CompressedBuffer, int Level) {
llvm_unreachable("zlib::compress is unavailable");
}
-Error zlib::uncompress(ArrayRef<uint8_t> Input, uint8_t *UncompressedBuffer,
+Error zlib::decompress(ArrayRef<uint8_t> Input, uint8_t *UncompressedBuffer,
size_t &UncompressedSize) {
- llvm_unreachable("zlib::uncompress is unavailable");
+ llvm_unreachable("zlib::decompress is unavailable");
}
-Error zlib::uncompress(ArrayRef<uint8_t> Input,
+Error zlib::decompress(ArrayRef<uint8_t> Input,
SmallVectorImpl<uint8_t> &UncompressedBuffer,
size_t UncompressedSize) {
- llvm_unreachable("zlib::uncompress is unavailable");
+ llvm_unreachable("zlib::decompress is unavailable");
}
#endif
@@ -170,28 +168,26 @@ void zstd::compress(ArrayRef<uint8_t> Input,
CompressedBuffer.truncate(CompressedSize);
}
-Error zstd::uncompress(ArrayRef<uint8_t> Input, uint8_t *UncompressedBuffer,
+Error zstd::decompress(ArrayRef<uint8_t> Input, uint8_t *Output,
size_t &UncompressedSize) {
- const size_t Res =
- ::ZSTD_decompress(UncompressedBuffer, UncompressedSize,
- (const uint8_t *)Input.data(), Input.size());
+ const size_t Res = ::ZSTD_decompress(
+ Output, UncompressedSize, (const uint8_t *)Input.data(), Input.size());
UncompressedSize = Res;
// Tell MemorySanitizer that zstd output buffer is fully initialized.
// This avoids a false report when running LLVM with uninstrumented ZLib.
- __msan_unpoison(UncompressedBuffer, UncompressedSize);
+ __msan_unpoison(Output, UncompressedSize);
return ZSTD_isError(Res) ? make_error<StringError>(ZSTD_getErrorName(Res),
inconvertibleErrorCode())
: Error::success();
}
-Error zstd::uncompress(ArrayRef<uint8_t> Input,
- SmallVectorImpl<uint8_t> &UncompressedBuffer,
+Error zstd::decompress(ArrayRef<uint8_t> Input,
+ SmallVectorImpl<uint8_t> &Output,
size_t UncompressedSize) {
- UncompressedBuffer.resize_for_overwrite(UncompressedSize);
- Error E =
- zstd::uncompress(Input, UncompressedBuffer.data(), UncompressedSize);
- if (UncompressedSize < UncompressedBuffer.size())
- UncompressedBuffer.truncate(UncompressedSize);
+ Output.resize_for_overwrite(UncompressedSize);
+ Error E = zstd::decompress(Input, Output.data(), UncompressedSize);
+ if (UncompressedSize < Output.size())
+ Output.truncate(UncompressedSize);
return E;
}
@@ -201,13 +197,13 @@ void zstd::compress(ArrayRef<uint8_t> Input,
SmallVectorImpl<uint8_t> &CompressedBuffer, int Level) {
llvm_unreachable("zstd::compress is unavailable");
}
-Error zstd::uncompress(ArrayRef<uint8_t> Input, uint8_t *UncompressedBuffer,
+Error zstd::decompress(ArrayRef<uint8_t> Input, uint8_t *Output,
size_t &UncompressedSize) {
- llvm_unreachable("zstd::uncompress is unavailable");
+ llvm_unreachable("zstd::decompress is unavailable");
}
-Error zstd::uncompress(ArrayRef<uint8_t> Input,
- SmallVectorImpl<uint8_t> &UncompressedBuffer,
+Error zstd::decompress(ArrayRef<uint8_t> Input,
+ SmallVectorImpl<uint8_t> &Output,
size_t UncompressedSize) {
- llvm_unreachable("zstd::uncompress is unavailable");
+ llvm_unreachable("zstd::decompress is unavailable");
}
#endif
diff --git a/llvm/unittests/Support/CompressionTest.cpp b/llvm/unittests/Support/CompressionTest.cpp
index c2314552f79ea..c887ff4189c77 100644
--- a/llvm/unittests/Support/CompressionTest.cpp
+++ b/llvm/unittests/Support/CompressionTest.cpp
@@ -29,19 +29,19 @@ static void testZlibCompression(StringRef Input, int Level) {
zlib::compress(arrayRefFromStringRef(Input), Compressed, Level);
// Check that uncompressed buffer is the same as original.
- Error E = zlib::uncompress(Compressed, Uncompressed, Input.size());
+ Error E = zlib::decompress(Compressed, Uncompressed, Input.size());
EXPECT_FALSE(std::move(E));
EXPECT_EQ(Input, toStringRef(Uncompressed));
- // decompress with Z dispatches to zlib::uncompress.
+ // decompress with Z dispatches to zlib::decompress.
E = compression::decompress(DebugCompressionType::Zlib, Compressed,
Uncompressed, Input.size());
EXPECT_FALSE(std::move(E));
EXPECT_EQ(Input, toStringRef(Uncompressed));
if (Input.size() > 0) {
- // Uncompression fails if expected length is too short.
- E = zlib::uncompress(Compressed, Uncompressed, Input.size() - 1);
+ // Decompression fails if expected length is too short.
+ E = zlib::decompress(Compressed, Uncompressed, Input.size() - 1);
EXPECT_EQ("zlib error: Z_BUF_ERROR", llvm::toString(std::move(E)));
}
}
@@ -74,19 +74,19 @@ static void testZstdCompression(StringRef Input, int Level) {
zstd::compress(arrayRefFromStringRef(Input), Compressed, Level);
// Check that uncompressed buffer is the same as original.
- Error E = zstd::uncompress(Compressed, Uncompressed, Input.size());
+ Error E = zstd::decompress(Compressed, Uncompressed, Input.size());
EXPECT_FALSE(std::move(E));
EXPECT_EQ(Input, toStringRef(Uncompressed));
- // uncompress with Zstd dispatches to zstd::uncompress.
+ // decompress with Zstd dispatches to zstd::decompress.
E = compression::decompress(DebugCompressionType::Zstd, Compressed,
Uncompressed, Input.size());
EXPECT_FALSE(std::move(E));
EXPECT_EQ(Input, toStringRef(Uncompressed));
if (Input.size() > 0) {
- // Uncompression fails if expected length is too short.
- E = zstd::uncompress(Compressed, Uncompressed, Input.size() - 1);
+ // Decompression fails if expected length is too short.
+ E = zstd::decompress(Compressed, Uncompressed, Input.size() - 1);
EXPECT_EQ("Destination buffer is too small", llvm::toString(std::move(E)));
}
}
More information about the llvm-commits
mailing list