This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by ArcsinX on Sep 15 2020, 1:00 AM.

Details

Summary

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

Diff Detail

Event Timeline

ArcsinX created this revision.Sep 15 2020, 1:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 15 2020, 1:00 AM
ArcsinX requested review of this revision.Sep 15 2020, 1:00 AM

Unsure about test for this

ArcsinX updated this revision to Diff 291827.Sep 15 2020, 1:24 AM

Fix build

adamcz accepted this revision.Sep 15 2020, 10:41 AM
adamcz added inline comments.
clang-tools-extra/clangd/index/Serialization.cpp
209

nit: skip { } to stay consistent with local style

This revision is now accepted and ready to land.Sep 15 2020, 10:41 AM
ArcsinX updated this revision to Diff 292116.Sep 15 2020, 11:28 PM

Remove {}

ArcsinX edited the summary of this revision. (Show Details)Sep 15 2020, 11:30 PM
sammccall accepted this revision.Sep 16 2020, 12:33 AM

Thanks, this seems better than crashing.
The practical result isn't wonderful: the two are going to fight over index files to some extent. But this can happen with different clangd versions (that use different index format versions) anyway. So this is really just graceful recovery from a bad situation.

Unsure about test for this

Agree, testing this seems hard and not that useful.

This revision was landed with ongoing or failed builds.Sep 16 2020, 1:06 AM
This revision was automatically updated to reflect the committed changes.

Thanks, this seems better than crashing.
The practical result isn't wonderful: the two are going to fight over index files to some extent. But this can happen with different clangd versions (that use different index format versions) anyway. So this is really just graceful recovery from a bad situation.

Unsure about test for this

Agree, testing this seems hard and not that useful.

FWIW here's how to test codepaths only reachable when zlib is not available:

./llvm/test/tools/llvm-dwp/X86/nocompress.test:

REQUIRES: !zlib

Thanks, this seems better than crashing.
The practical result isn't wonderful: the two are going to fight over index files to some extent. But this can happen with different clangd versions (that use different index format versions) anyway. So this is really just graceful recovery from a bad situation.

Unsure about test for this

Agree, testing this seems hard and not that useful.

FWIW here's how to test codepaths only reachable when zlib is not available:

./llvm/test/tools/llvm-dwp/X86/nocompress.test:

REQUIRES: !zlib

Yep, that requires a checked-in binary file, which in the case of that test is in a standard stable format, which this data is not, so we'd also need tools to regenerate it. And we don't have APIs to generate the file without compression if zlib is available (because we never want to do that), so we'd need to add those or require anyone touching the file format to build a no-zlib tree to regenerate the file.
None of this is impossible, but this is pretty unlikely to catch a bug, and it's very unlikely to be a high-impact bug..

Thanks, this seems better than crashing.
The practical result isn't wonderful: the two are going to fight over index files to some extent. But this can happen with different clangd versions (that use different index format versions) anyway. So this is really just graceful recovery from a bad situation.

Unsure about test for this

Agree, testing this seems hard and not that useful.

FWIW here's how to test codepaths only reachable when zlib is not available:

./llvm/test/tools/llvm-dwp/X86/nocompress.test:

REQUIRES: !zlib

Yep, that requires a checked-in binary file, which in the case of that test is in a standard stable format, which this data is not, so we'd also need tools to regenerate it. And we don't have APIs to generate the file without compression if zlib is available (because we never want to do that), so we'd need to add those or require anyone touching the file format to build a no-zlib tree to regenerate the file.
None of this is impossible, but this is pretty unlikely to catch a bug, and it's very unlikely to be a high-impact bug..

Ah, fair enough. Might be nice to have a flag to request the uncompressed behavior even when compression's available - for testing purposes and such, but given the current implementation, yeah, don't see a tidy way to test it.