[clang-tools-extra] d427df6 - [clangd] Don't use zlib when it's unavailable.

Aleksandr Platonov via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 16 01:06:15 PDT 2020


Author: Aleksandr Platonov
Date: 2020-09-16T11:05:18+03:00
New Revision: d427df6369f1d229a9f498b4dc621433ada380d2

URL: https://github.com/llvm/llvm-project/commit/d427df6369f1d229a9f498b4dc621433ada380d2
DIFF: https://github.com/llvm/llvm-project/commit/d427df6369f1d229a9f498b4dc621433ada380d2.diff

LOG: [clangd] Don't use zlib when it's unavailable.

Without this patch `clangd` crashes at try to load compressed string table when `zlib` is not available.
Example:
- Build `clangd` with MinGW (`zlib` found)
- Build index
- Build `clangd` with Visual Studio compiler (`zlib` not found)
- Try to load index

Reviewed By: sammccall, adamcz

Differential Revision: https://reviews.llvm.org/D87673

Added: 
    

Modified: 
    clang-tools-extra/clangd/index/Serialization.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/index/Serialization.cpp b/clang-tools-extra/clangd/index/Serialization.cpp
index c099a30c4d34..e7f65f087b1c 100644
--- a/clang-tools-extra/clangd/index/Serialization.cpp
+++ b/clang-tools-extra/clangd/index/Serialization.cpp
@@ -201,12 +201,13 @@ llvm::Expected<StringTableIn> readStringTable(llvm::StringRef Data) {
   llvm::SmallString<1> UncompressedStorage;
   if (UncompressedSize == 0) // No compression
     Uncompressed = R.rest();
-  else {
+  else if (llvm::zlib::isAvailable()) {
     if (llvm::Error E = llvm::zlib::uncompress(R.rest(), UncompressedStorage,
                                                UncompressedSize))
       return std::move(E);
     Uncompressed = UncompressedStorage;
-  }
+  } else
+    return error("Compressed string table, but zlib is unavailable");
 
   StringTableIn Table;
   llvm::StringSaver Saver(Table.Arena);


        


More information about the cfe-commits mailing list