[PATCH] D28807: [Clang] - Update code to match upcoming llvm::zlib API.
Rafael Avila de Espindola via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 17 07:47:13 PST 2017
LGTM
George Rimar via Phabricator <reviews at reviews.llvm.org> writes:
> grimar created this revision.
>
> https://reviews.llvm.org/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.
>
>
> https://reviews.llvm.org/D28807
>
> Files:
> lib/Serialization/ASTReader.cpp
> lib/Serialization/ASTWriter.cpp
>
>
> Index: lib/Serialization/ASTWriter.cpp
> ===================================================================
> --- lib/Serialization/ASTWriter.cpp
> +++ lib/Serialization/ASTWriter.cpp
> @@ -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 @@
> 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 @@
> 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.
> Index: lib/Serialization/ASTReader.cpp
> ===================================================================
> --- lib/Serialization/ASTReader.cpp
> +++ lib/Serialization/ASTReader.cpp
> @@ -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 @@
> 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);
>
>
> Index: lib/Serialization/ASTWriter.cpp
> ===================================================================
> --- lib/Serialization/ASTWriter.cpp
> +++ lib/Serialization/ASTWriter.cpp
> @@ -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 @@
> 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 @@
> 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.
> Index: lib/Serialization/ASTReader.cpp
> ===================================================================
> --- lib/Serialization/ASTReader.cpp
> +++ lib/Serialization/ASTReader.cpp
> @@ -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 @@
> 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);
More information about the cfe-commits
mailing list