[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
This commit is contained in:
Aleksandr Platonov 2020-09-16 11:04:53 +03:00
parent 070b96962f
commit d427df6369
1 changed files with 3 additions and 2 deletions

View File

@ -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);