[ASTReader] Fix zlib header detection 0x78 after D137885

D137885 picked an incorrect magic so it would fail when zstd is not
enabled.
This commit is contained in:
Fangrui Song 2022-11-23 13:22:44 -08:00
parent bfc812a2f3
commit 8f43b84322
1 changed files with 3 additions and 2 deletions

View File

@ -1452,9 +1452,10 @@ bool ASTReader::ReadSLocEntry(int ID) {
unsigned RecCode = MaybeRecCode.get();
if (RecCode == SM_SLOC_BUFFER_BLOB_COMPRESSED) {
// Inspect the first two bytes to differentiate zlib (\x1f\x8b) and zstd.
// Inspect the first byte to differentiate zlib (\x78) and zstd
// (little-endian 0xFD2FB528).
const llvm::compression::Format F =
Blob.size() >= 2 && memcmp(Blob.data(), "\x1f\x8b", 2) == 0
Blob.size() > 0 && Blob.data()[0] == 0x78
? llvm::compression::Format::Zlib
: llvm::compression::Format::Zstd;
if (const char *Reason = llvm::compression::getReasonIfUnsupported(F)) {