@@ -1824,6 +1824,27 @@ struct InputFileEntry {
1824
1824
uint32_t ContentHash[2 ];
1825
1825
1826
1826
InputFileEntry (FileEntryRef File) : File(File) {}
1827
+
1828
+ void trySetContentHash (Preprocessor &PP,
1829
+ std::optional<llvm::MemoryBufferRef> MemBuff) {
1830
+ if (!PP.getHeaderSearchInfo ()
1831
+ .getHeaderSearchOpts ()
1832
+ .ValidateASTInputFilesContent ) {
1833
+ ContentHash[0 ] = 0 ;
1834
+ ContentHash[1 ] = 0 ;
1835
+ return ;
1836
+ }
1837
+
1838
+ if (!MemBuff) {
1839
+ PP.Diag (SourceLocation (), diag::err_module_unable_to_hash_content)
1840
+ << File.getName ();
1841
+ return ;
1842
+ }
1843
+
1844
+ uint64_t Hash = xxh3_64bits (MemBuff->getBuffer ());
1845
+ ContentHash[0 ] = uint32_t (Hash);
1846
+ ContentHash[1 ] = uint32_t (Hash >> 32 );
1847
+ }
1827
1848
};
1828
1849
1829
1850
} // namespace
@@ -1898,25 +1919,36 @@ void ASTWriter::WriteInputFiles(SourceManager &SourceMgr) {
1898
1919
!IsSLocFileEntryAffecting[IncludeFileID.ID ];
1899
1920
Entry.IsModuleMap = isModuleMap (File.getFileCharacteristic ());
1900
1921
1901
- uint64_t ContentHash = 0 ;
1902
- if (PP->getHeaderSearchInfo ()
1903
- .getHeaderSearchOpts ()
1904
- .ValidateASTInputFilesContent ) {
1905
- auto MemBuff = Cache->getBufferIfLoaded ();
1906
- if (MemBuff)
1907
- ContentHash = xxh3_64bits (MemBuff->getBuffer ());
1908
- else
1909
- PP->Diag (SourceLocation (), diag::err_module_unable_to_hash_content)
1910
- << Entry.File .getName ();
1911
- }
1912
- Entry.ContentHash [0 ] = uint32_t (ContentHash);
1913
- Entry.ContentHash [1 ] = uint32_t (ContentHash >> 32 );
1922
+ Entry.trySetContentHash (*PP, Cache->getBufferIfLoaded ());
1923
+
1914
1924
if (Entry.IsSystemFile )
1915
1925
SystemFiles.push_back (Entry);
1916
1926
else
1917
1927
UserFiles.push_back (Entry);
1918
1928
}
1919
1929
1930
+ // FIXME: This is here because the include-tree file list refers to this file
1931
+ // and we need to validate it's up-to-date when reading the AST file. Make
1932
+ // this more generic and include the remaining files.
1933
+ StringRef Sysroot = PP->getHeaderSearchInfo ().getHeaderSearchOpts ().Sysroot ;
1934
+ if (!Sysroot.empty ()) {
1935
+ SmallString<128 > SDKSettingsJSON = Sysroot;
1936
+ llvm::sys::path::append (SDKSettingsJSON, " SDKSettings.json" );
1937
+ if (auto FE = PP->getFileManager ().getOptionalFileRef (SDKSettingsJSON)) {
1938
+ InputFileEntry Entry (*FE);
1939
+ Entry.IsSystemFile = true ;
1940
+ Entry.IsTransient = false ;
1941
+ Entry.BufferOverridden = false ;
1942
+ Entry.IsTopLevel = true ;
1943
+ Entry.IsModuleMap = false ;
1944
+ if (auto BuffOrErr = PP->getFileManager ().getBufferForFile (Entry.File ))
1945
+ Entry.trySetContentHash (*PP, (*BuffOrErr)->getMemBufferRef ());
1946
+ else
1947
+ Entry.trySetContentHash (*PP, {});
1948
+ SystemFiles.push_back (Entry);
1949
+ }
1950
+ }
1951
+
1920
1952
// User files go at the front, system files at the back.
1921
1953
auto SortedFiles = llvm::concat<InputFileEntry>(std::move (UserFiles),
1922
1954
std::move (SystemFiles));
@@ -5950,18 +5982,6 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema *SemaPtr, StringRef isysroot,
5950
5982
if (Chain)
5951
5983
Chain->finalizeForWriting ();
5952
5984
5953
- // FIXME: This is here because the include-tree file list refers to this file
5954
- // and we need to validate it's up-to-date when reading the AST file. Make
5955
- // this more generic and include the remaining files.
5956
- StringRef Sysroot = PP->getHeaderSearchInfo ().getHeaderSearchOpts ().Sysroot ;
5957
- if (!Sysroot.empty ()) {
5958
- SmallString<128 > SDKSettingsJSON = Sysroot;
5959
- llvm::sys::path::append (SDKSettingsJSON, " SDKSettings.json" );
5960
- if (auto FE = PP->getFileManager ().getOptionalFileRef (SDKSettingsJSON))
5961
- PP->getSourceManager ().createFileID (*FE, SourceLocation (),
5962
- SrcMgr::C_System);
5963
- }
5964
-
5965
5985
// This needs to be done very early, since everything that writes
5966
5986
// SourceLocations or FileIDs depends on it.
5967
5987
computeNonAffectingInputFiles ();
0 commit comments