Skip to content

Commit cb7f91d

Browse files
MaskRayAlexisPerry
authored andcommitted
[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 llvm#96379: llvm#96136 switched the hash function to xxh3_64bit but did not update the ContentHash type, leading to mismatch between ASTReader and ASTWriter.
1 parent 8cc7ee4 commit cb7f91d

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

clang/lib/Serialization/ASTReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2629,7 +2629,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
26292629
"We should only check the content of the inputs with "
26302630
"ValidateASTInputFilesContent enabled.");
26312631

2632-
if (StoredContentHash == static_cast<uint64_t>(llvm::hash_code(-1)))
2632+
if (StoredContentHash == 0)
26332633
return OriginalChange;
26342634

26352635
auto MemBuffOrError = FileMgr.getBufferForFile(*File);

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,7 +1776,7 @@ void ASTWriter::WriteInputFiles(SourceManager &SourceMgr,
17761776
Entry.IsTopLevel = getAffectingIncludeLoc(SourceMgr, File).isInvalid();
17771777
Entry.IsModuleMap = isModuleMap(File.getFileCharacteristic());
17781778

1779-
auto ContentHash = hash_code(-1);
1779+
uint64_t ContentHash = 0;
17801780
if (PP->getHeaderSearchInfo()
17811781
.getHeaderSearchOpts()
17821782
.ValidateASTInputFilesContent) {
@@ -1787,12 +1787,8 @@ void ASTWriter::WriteInputFiles(SourceManager &SourceMgr,
17871787
PP->Diag(SourceLocation(), diag::err_module_unable_to_hash_content)
17881788
<< Entry.File.getName();
17891789
}
1790-
auto CH = llvm::APInt(64, ContentHash);
1791-
Entry.ContentHash[0] =
1792-
static_cast<uint32_t>(CH.getLoBits(32).getZExtValue());
1793-
Entry.ContentHash[1] =
1794-
static_cast<uint32_t>(CH.getHiBits(32).getZExtValue());
1795-
1790+
Entry.ContentHash[0] = uint32_t(ContentHash);
1791+
Entry.ContentHash[1] = uint32_t(ContentHash >> 32);
17961792
if (Entry.IsSystemFile)
17971793
SystemFiles.push_back(Entry);
17981794
else

0 commit comments

Comments
 (0)