[clang] [llvm] [LLVM] Infer compression format from zlib and zstd headers (PR #222773)

James Henderson via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 28 03:11:54 PDT 2026


================
@@ -1927,19 +1927,15 @@ bool ASTReader::ReadSLocEntry(int ID) {
     unsigned RecCode = MaybeRecCode.get();
 
     if (RecCode == SM_SLOC_BUFFER_BLOB_COMPRESSED) {
-      // Inspect the first byte to differentiate zlib (\x78) and zstd
-      // (little-endian 0xFD2FB528).
-      const llvm::compression::Format F =
-          Blob.size() > 0 && Blob.data()[0] == 0x78
-              ? llvm::compression::Format::Zlib
-              : llvm::compression::Format::Zstd;
-      if (const char *Reason = llvm::compression::getReasonIfUnsupported(F)) {
+      ArrayRef<uint8_t> Compressed = llvm::arrayRefFromStringRef(Blob);
+      if (const char *Reason =
+              llvm::compression::getReasonIfUnsupported(Compressed)) {
         Error(Reason);
         return nullptr;
       }
----------------
jh7370 wrote:

Can't we just use the return from `decompress` here, since this `decompress` overload calls `getReasonIfUnsupported` and stuffs it into the `Error`? I think if this causes a slight change in the error message, that's fine (though I imagine it would mean fixing up a test or two).

https://github.com/llvm/llvm-project/pull/222773


More information about the cfe-commits mailing list