summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2017-01-17 13:27:58 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2017-01-17 13:27:58 +0000
commit715540f20740ff86706dd7437b7239e1a163769d (patch)
tree1634e9bae417ba6f27540cc6f345a41b8ec2c2f7
parenta2a0213179de235f0423e520b6625c696a9daff6 (diff)
downloadbcm5719-llvm-715540f20740ff86706dd7437b7239e1a163769d.tar.gz
bcm5719-llvm-715540f20740ff86706dd7437b7239e1a163769d.zip
Revert r292214 "[Support/Compression] - Change zlib API to return Error instead of custom status."
It broked clang: http://lab.llvm.org:8080/green//job/clang-stage1-cmake-RA-incremental_build/34218/consoleFull#46141505449ba4694-19c4-4d7e-bec5-911270d8a58c llvm-svn: 292217
-rw-r--r--llvm/include/llvm/Support/Compression.h24
-rw-r--r--llvm/lib/MC/ELFObjectWriter.cpp9
-rw-r--r--llvm/lib/Object/Decompressor.cpp5
-rw-r--r--llvm/lib/ProfileData/InstrProf.cpp17
-rw-r--r--llvm/lib/Support/Compression.cpp83
-rw-r--r--llvm/unittests/Support/CompressionTest.cpp17
6 files changed, 72 insertions, 83 deletions
diff --git a/llvm/include/llvm/Support/Compression.h b/llvm/include/llvm/Support/Compression.h
index 2d191abe4b1..5bf7031fe9f 100644
--- a/llvm/include/llvm/Support/Compression.h
+++ b/llvm/include/llvm/Support/Compression.h
@@ -18,7 +18,6 @@
namespace llvm {
template <typename T> class SmallVectorImpl;
-class Error;
class StringRef;
namespace zlib {
@@ -30,17 +29,26 @@ enum CompressionLevel {
BestSizeCompression
};
+enum Status {
+ StatusOK,
+ StatusUnsupported, // zlib is unavailable
+ StatusOutOfMemory, // there was not enough memory
+ StatusBufferTooShort, // there was not enough room in the output buffer
+ StatusInvalidArg, // invalid input parameter
+ StatusInvalidData // data was corrupted or incomplete
+};
+
bool isAvailable();
-Error compress(StringRef InputBuffer, SmallVectorImpl<char> &CompressedBuffer,
- CompressionLevel Level = DefaultCompression);
+Status compress(StringRef InputBuffer, SmallVectorImpl<char> &CompressedBuffer,
+ CompressionLevel Level = DefaultCompression);
-Error uncompress(StringRef InputBuffer, char *UncompressedBuffer,
- size_t &UncompressedSize);
+Status uncompress(StringRef InputBuffer, char *UncompressedBuffer,
+ size_t &UncompressedSize);
-Error uncompress(StringRef InputBuffer,
- SmallVectorImpl<char> &UncompressedBuffer,
- size_t UncompressedSize);
+Status uncompress(StringRef InputBuffer,
+ SmallVectorImpl<char> &UncompressedBuffer,
+ size_t UncompressedSize);
uint32_t crc32(StringRef Buffer);
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 0e02cdb4ca0..a8c88dda693 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -32,7 +32,6 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/ELF.h"
#include "llvm/Support/Endian.h"
-#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/StringSaver.h"
#include <vector>
@@ -1038,10 +1037,10 @@ void ELFObjectWriter::writeSectionData(const MCAssembler &Asm, MCSection &Sec,
setStream(OldStream);
SmallVector<char, 128> CompressedContents;
- if (Error E = zlib::compress(
- StringRef(UncompressedData.data(), UncompressedData.size()),
- CompressedContents)) {
- consumeError(std::move(E));
+ zlib::Status Success = zlib::compress(
+ StringRef(UncompressedData.data(), UncompressedData.size()),
+ CompressedContents);
+ if (Success != zlib::StatusOK) {
getStream() << UncompressedData;
return;
}
diff --git a/llvm/lib/Object/Decompressor.cpp b/llvm/lib/Object/Decompressor.cpp
index 0be602b1fc1..bca41fd9f48 100644
--- a/llvm/lib/Object/Decompressor.cpp
+++ b/llvm/lib/Object/Decompressor.cpp
@@ -95,5 +95,8 @@ Error Decompressor::decompress(SmallString<32> &Out) {
Error Decompressor::decompress(MutableArrayRef<char> Buffer) {
size_t Size = Buffer.size();
- return zlib::uncompress(SectionData, Buffer.data(), Size);
+ zlib::Status Status = zlib::uncompress(SectionData, Buffer.data(), Size);
+ if (Status != zlib::StatusOK)
+ return createError("decompression failed");
+ return Error::success();
}
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index eb676602632..74acd9e5e20 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -271,12 +271,12 @@ Error collectPGOFuncNameStrings(const std::vector<std::string> &NameStrs,
}
SmallString<128> CompressedNameStrings;
- Error E = zlib::compress(StringRef(UncompressedNameStrings),
- CompressedNameStrings, zlib::BestSizeCompression);
- if (E) {
- consumeError(std::move(E));
+ zlib::Status Success =
+ zlib::compress(StringRef(UncompressedNameStrings), CompressedNameStrings,
+ zlib::BestSizeCompression);
+
+ if (Success != zlib::StatusOK)
return make_error<InstrProfError>(instrprof_error::compress_failed);
- }
return WriteStringToResult(CompressedNameStrings.size(),
CompressedNameStrings);
@@ -315,12 +315,9 @@ Error readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab) {
if (isCompressed) {
StringRef CompressedNameStrings(reinterpret_cast<const char *>(P),
CompressedSize);
- if (Error E =
- zlib::uncompress(CompressedNameStrings, UncompressedNameStrings,
- UncompressedSize)) {
- consumeError(std::move(E));
+ if (zlib::uncompress(CompressedNameStrings, UncompressedNameStrings,
+ UncompressedSize) != zlib::StatusOK)
return make_error<InstrProfError>(instrprof_error::uncompress_failed);
- }
P += CompressedSize;
NameStrings = StringRef(UncompressedNameStrings.data(),
UncompressedNameStrings.size());
diff --git a/llvm/lib/Support/Compression.cpp b/llvm/lib/Support/Compression.cpp
index c279d10f6c6..5d556462e89 100644
--- a/llvm/lib/Support/Compression.cpp
+++ b/llvm/lib/Support/Compression.cpp
@@ -16,7 +16,6 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Config/config.h"
#include "llvm/Support/Compiler.h"
-#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#if LLVM_ENABLE_ZLIB == 1 && HAVE_ZLIB_H
#include <zlib.h>
@@ -25,10 +24,6 @@
using namespace llvm;
#if LLVM_ENABLE_ZLIB == 1 && HAVE_LIBZ
-static Error createError(StringRef Err) {
- return make_error<StringError>(Err, inconvertibleErrorCode());
-}
-
static int encodeZlibCompressionLevel(zlib::CompressionLevel Level) {
switch (Level) {
case zlib::NoCompression: return 0;
@@ -39,59 +34,53 @@ static int encodeZlibCompressionLevel(zlib::CompressionLevel Level) {
llvm_unreachable("Invalid zlib::CompressionLevel!");
}
-static StringRef convertZlibCodeToString(int Code) {
- switch (Code) {
- case Z_MEM_ERROR:
- return "zlib error: Z_MEM_ERROR";
- case Z_BUF_ERROR:
- return "zlib error: Z_BUF_ERROR";
- case Z_STREAM_ERROR:
- return "zlib error: Z_STREAM_ERROR";
- case Z_DATA_ERROR:
- return "zlib error: Z_DATA_ERROR";
- case Z_OK:
- default:
- llvm_unreachable("unknown or unexpected zlib status code");
+static zlib::Status encodeZlibReturnValue(int ReturnValue) {
+ switch (ReturnValue) {
+ case Z_OK: return zlib::StatusOK;
+ case Z_MEM_ERROR: return zlib::StatusOutOfMemory;
+ case Z_BUF_ERROR: return zlib::StatusBufferTooShort;
+ case Z_STREAM_ERROR: return zlib::StatusInvalidArg;
+ case Z_DATA_ERROR: return zlib::StatusInvalidData;
+ default: llvm_unreachable("unknown zlib return status!");
}
}
bool zlib::isAvailable() { return true; }
-
-Error zlib::compress(StringRef InputBuffer,
- SmallVectorImpl<char> &CompressedBuffer,
- CompressionLevel Level) {
+zlib::Status zlib::compress(StringRef InputBuffer,
+ SmallVectorImpl<char> &CompressedBuffer,
+ CompressionLevel Level) {
unsigned long CompressedSize = ::compressBound(InputBuffer.size());
CompressedBuffer.resize(CompressedSize);
int CLevel = encodeZlibCompressionLevel(Level);
- int Res = ::compress2((Bytef *)CompressedBuffer.data(), &CompressedSize,
- (const Bytef *)InputBuffer.data(), InputBuffer.size(),
- CLevel);
+ Status Res = encodeZlibReturnValue(::compress2(
+ (Bytef *)CompressedBuffer.data(), &CompressedSize,
+ (const Bytef *)InputBuffer.data(), InputBuffer.size(), CLevel));
// 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.resize(CompressedSize);
- return Res ? createError(convertZlibCodeToString(Res)) : Error::success();
+ return Res;
}
-Error zlib::uncompress(StringRef InputBuffer, char *UncompressedBuffer,
- size_t &UncompressedSize) {
- int Res =
+zlib::Status zlib::uncompress(StringRef InputBuffer, char *UncompressedBuffer,
+ size_t &UncompressedSize) {
+ Status Res = encodeZlibReturnValue(
::uncompress((Bytef *)UncompressedBuffer, (uLongf *)&UncompressedSize,
- (const Bytef *)InputBuffer.data(), InputBuffer.size());
+ (const Bytef *)InputBuffer.data(), InputBuffer.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);
- return Res ? createError(convertZlibCodeToString(Res)) : Error::success();
+ return Res;
}
-Error zlib::uncompress(StringRef InputBuffer,
- SmallVectorImpl<char> &UncompressedBuffer,
- size_t UncompressedSize) {
+zlib::Status zlib::uncompress(StringRef InputBuffer,
+ SmallVectorImpl<char> &UncompressedBuffer,
+ size_t UncompressedSize) {
UncompressedBuffer.resize(UncompressedSize);
- Error E =
+ Status Res =
uncompress(InputBuffer, UncompressedBuffer.data(), UncompressedSize);
UncompressedBuffer.resize(UncompressedSize);
- return E;
+ return Res;
}
uint32_t zlib::crc32(StringRef Buffer) {
@@ -100,19 +89,19 @@ uint32_t zlib::crc32(StringRef Buffer) {
#else
bool zlib::isAvailable() { return false; }
-Error zlib::compress(StringRef InputBuffer,
- SmallVectorImpl<char> &CompressedBuffer,
- CompressionLevel Level) {
- llvm_unreachable("zlib::compress is unavailable");
+zlib::Status zlib::compress(StringRef InputBuffer,
+ SmallVectorImpl<char> &CompressedBuffer,
+ CompressionLevel Level) {
+ return zlib::StatusUnsupported;
}
-Error zlib::uncompress(StringRef InputBuffer, char *UncompressedBuffer,
- size_t &UncompressedSize) {
- llvm_unreachable("zlib::uncompress is unavailable");
+zlib::Status zlib::uncompress(StringRef InputBuffer, char *UncompressedBuffer,
+ size_t &UncompressedSize) {
+ return zlib::StatusUnsupported;
}
-Error zlib::uncompress(StringRef InputBuffer,
- SmallVectorImpl<char> &UncompressedBuffer,
- size_t UncompressedSize) {
- llvm_unreachable("zlib::uncompress is unavailable");
+zlib::Status zlib::uncompress(StringRef InputBuffer,
+ SmallVectorImpl<char> &UncompressedBuffer,
+ size_t UncompressedSize) {
+ return zlib::StatusUnsupported;
}
uint32_t zlib::crc32(StringRef Buffer) {
llvm_unreachable("zlib::crc32 is unavailable");
diff --git a/llvm/unittests/Support/CompressionTest.cpp b/llvm/unittests/Support/CompressionTest.cpp
index 18a6175460d..36b84d85f22 100644
--- a/llvm/unittests/Support/CompressionTest.cpp
+++ b/llvm/unittests/Support/CompressionTest.cpp
@@ -12,7 +12,6 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/Compression.h"
-#include "llvm/Support/Error.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Config/config.h"
@@ -27,21 +26,15 @@ namespace {
void TestZlibCompression(StringRef Input, zlib::CompressionLevel Level) {
SmallString<32> Compressed;
SmallString<32> Uncompressed;
-
- Error E = zlib::compress(Input, Compressed, Level);
- EXPECT_FALSE(E);
- consumeError(std::move(E));
-
+ EXPECT_EQ(zlib::StatusOK, zlib::compress(Input, Compressed, Level));
// Check that uncompressed buffer is the same as original.
- E = zlib::uncompress(Compressed, Uncompressed, Input.size());
- EXPECT_FALSE(E);
- consumeError(std::move(E));
-
+ EXPECT_EQ(zlib::StatusOK,
+ zlib::uncompress(Compressed, Uncompressed, Input.size()));
EXPECT_EQ(Input, Uncompressed);
if (Input.size() > 0) {
// Uncompression fails if expected length is too short.
- E = zlib::uncompress(Compressed, Uncompressed, Input.size() - 1);
- EXPECT_EQ("zlib error: Z_BUF_ERROR", llvm::toString(std::move(E)));
+ EXPECT_EQ(zlib::StatusBufferTooShort,
+ zlib::uncompress(Compressed, Uncompressed, Input.size() - 1));
}
}
OpenPOWER on IntegriCloud