aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-06-22 14:21:36 -0700
committerFangrui Song <i@maskray.me>2024-06-22 14:21:36 -0700
commitf3005d5b86ca947977f6056552b2a4648b9f0460 (patch)
treecb882fd508818ff4d65eb01ed960ce6ae1c47d46
parent3ba7599842be852abdad9db2ad75c35263ad517e (diff)
downloadllvm-f3005d5b86ca947977f6056552b2a4648b9f0460.zip
llvm-f3005d5b86ca947977f6056552b2a4648b9f0460.tar.gz
llvm-f3005d5b86ca947977f6056552b2a4648b9f0460.tar.bz2
[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.
-rw-r--r--clang/lib/Serialization/ASTReader.cpp2
-rw-r--r--clang/lib/Serialization/ASTWriter.cpp10
2 files changed, 4 insertions, 8 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index c0b7db7..e8b3986 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 e6a58dc..d99d856 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