forked from OSchip/llvm-project
[Clang] - Update code to match upcoming llvm::zlib API.
D28684 changed llvm::zlib to return Error instead of Status. It was accepted and committed in r292214, but then reverted in r292217 because I missed that clang code also needs to be updated. Patch do that. D28684 recommitted again as r292226 Differential revision: https://reviews.llvm.org/D28807 llvm-svn: 292227
This commit is contained in:
parent
167ca4ae7e
commit
c39f5491a4
|
@ -72,6 +72,7 @@
|
|||
#include "llvm/Bitcode/BitstreamReader.h"
|
||||
#include "llvm/Support/Compression.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
|
@ -1278,10 +1279,15 @@ bool ASTReader::ReadSLocEntry(int ID) {
|
|||
unsigned RecCode = SLocEntryCursor.readRecord(Code, Record, &Blob);
|
||||
|
||||
if (RecCode == SM_SLOC_BUFFER_BLOB_COMPRESSED) {
|
||||
if (!llvm::zlib::isAvailable()) {
|
||||
Error("zlib is not available");
|
||||
return nullptr;
|
||||
}
|
||||
SmallString<0> Uncompressed;
|
||||
if (llvm::zlib::uncompress(Blob, Uncompressed, Record[0]) !=
|
||||
llvm::zlib::StatusOK) {
|
||||
Error("could not decompress embedded file contents");
|
||||
if (llvm::Error E =
|
||||
llvm::zlib::uncompress(Blob, Uncompressed, Record[0])) {
|
||||
Error("could not decompress embedded file contents: " +
|
||||
llvm::toString(std::move(E)));
|
||||
return nullptr;
|
||||
}
|
||||
return llvm::MemoryBuffer::getMemBufferCopy(Uncompressed, Name);
|
||||
|
|
|
@ -73,6 +73,7 @@
|
|||
#include "llvm/Support/Casting.h"
|
||||
#include "llvm/Support/Compression.h"
|
||||
#include "llvm/Support/EndianStream.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/OnDiskHashTable.h"
|
||||
|
@ -1986,6 +1987,30 @@ void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) {
|
|||
free(const_cast<char *>(SavedStrings[I]));
|
||||
}
|
||||
|
||||
static void emitBlob(llvm::BitstreamWriter &Stream, StringRef Blob,
|
||||
unsigned SLocBufferBlobCompressedAbbrv,
|
||||
unsigned SLocBufferBlobAbbrv) {
|
||||
typedef ASTWriter::RecordData::value_type RecordDataType;
|
||||
|
||||
// Compress the buffer if possible. We expect that almost all PCM
|
||||
// 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));
|
||||
}
|
||||
|
||||
RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB};
|
||||
Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, Blob);
|
||||
}
|
||||
|
||||
/// \brief Writes the block containing the serialized form of the
|
||||
/// source manager.
|
||||
///
|
||||
|
@ -2094,20 +2119,8 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
|
|||
const llvm::MemoryBuffer *Buffer =
|
||||
Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager());
|
||||
StringRef Blob(Buffer->getBufferStart(), Buffer->getBufferSize() + 1);
|
||||
|
||||
// Compress the buffer if possible. We expect that almost all PCM
|
||||
// consumers will not want its contents.
|
||||
SmallString<0> CompressedBuffer;
|
||||
if (llvm::zlib::compress(Blob.drop_back(1), CompressedBuffer) ==
|
||||
llvm::zlib::StatusOK) {
|
||||
RecordData::value_type Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED,
|
||||
Blob.size() - 1};
|
||||
Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record,
|
||||
CompressedBuffer);
|
||||
} else {
|
||||
RecordData::value_type Record[] = {SM_SLOC_BUFFER_BLOB};
|
||||
Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, Blob);
|
||||
}
|
||||
emitBlob(Stream, Blob, SLocBufferBlobCompressedAbbrv,
|
||||
SLocBufferBlobAbbrv);
|
||||
}
|
||||
} else {
|
||||
// The source location entry is a macro expansion.
|
||||
|
|
Loading…
Reference in New Issue