Author: Fangrui Song Date: 2024-06-22T14:21:36-07:00 New Revision: f3005d5b86ca947977f6056552b2a4648b9f0460
URL: https://github.com/llvm/llvm-project/commit/f3005d5b86ca947977f6056552b2a4648b9f0460 DIFF: https://github.com/llvm/llvm-project/commit/f3005d5b86ca947977f6056552b2a4648b9f0460.diff LOG: [Serialization] Change input file content hash from size_t to uint64_t https://reviews.llvm.org/D67249 added content hash (see -fvalidate-ast-input-files-content) using llvm::hash_code (size_t). The hash value is 32-bit on 32-bit systems, which was unintentional. Fix #96379: #96136 switched the hash function to xxh3_64bit but did not update the ContentHash type, leading to mismatch between ASTReader and ASTWriter. Added: Modified: clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTWriter.cpp Removed: ################################################################################ diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index c0b7db72fb603..e8b398615e0e1 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -2629,7 +2629,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { "We should only check the content of the inputs with " "ValidateASTInputFilesContent enabled."); - if (StoredContentHash == static_cast<uint64_t>(llvm::hash_code(-1))) + if (StoredContentHash == 0) return OriginalChange; auto MemBuffOrError = FileMgr.getBufferForFile(*File); diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index e6a58dcc61e3f..d99d85652c7b7 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -1776,7 +1776,7 @@ void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, Entry.IsTopLevel = getAffectingIncludeLoc(SourceMgr, File).isInvalid(); Entry.IsModuleMap = isModuleMap(File.getFileCharacteristic()); - auto ContentHash = hash_code(-1); + uint64_t ContentHash = 0; if (PP->getHeaderSearchInfo() .getHeaderSearchOpts() .ValidateASTInputFilesContent) { @@ -1787,12 +1787,8 @@ void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, PP->Diag(SourceLocation(), diag::err_module_unable_to_hash_content) << Entry.File.getName(); } - auto CH = llvm::APInt(64, ContentHash); - Entry.ContentHash[0] = - static_cast<uint32_t>(CH.getLoBits(32).getZExtValue()); - Entry.ContentHash[1] = - static_cast<uint32_t>(CH.getHiBits(32).getZExtValue()); - + Entry.ContentHash[0] = uint32_t(ContentHash); + Entry.ContentHash[1] = uint32_t(ContentHash >> 32); if (Entry.IsSystemFile) SystemFiles.push_back(Entry); else _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits