@@ -1771,6 +1771,29 @@ struct InputFileEntry {
1771
1771
uint32_t ContentHash[2 ];
1772
1772
1773
1773
InputFileEntry (FileEntryRef File) : File(File) {}
1774
+
1775
+ void trySetContentHash (
1776
+ Preprocessor &PP,
1777
+ llvm::function_ref<std::optional<llvm::MemoryBufferRef>()> GetMemBuff) {
1778
+ ContentHash[0 ] = 0 ;
1779
+ ContentHash[1 ] = 0 ;
1780
+
1781
+ if (!PP.getHeaderSearchInfo ()
1782
+ .getHeaderSearchOpts ()
1783
+ .ValidateASTInputFilesContent )
1784
+ return ;
1785
+
1786
+ auto MemBuff = GetMemBuff ();
1787
+ if (!MemBuff) {
1788
+ PP.Diag (SourceLocation (), diag::err_module_unable_to_hash_content)
1789
+ << File.getName ();
1790
+ return ;
1791
+ }
1792
+
1793
+ uint64_t Hash = xxh3_64bits (MemBuff->getBuffer ());
1794
+ ContentHash[0 ] = uint32_t (Hash);
1795
+ ContentHash[1 ] = uint32_t (Hash >> 32 );
1796
+ }
1774
1797
};
1775
1798
1776
1799
} // namespace
@@ -1843,25 +1866,41 @@ void ASTWriter::WriteInputFiles(SourceManager &SourceMgr,
1843
1866
Entry.IsTopLevel = getAffectingIncludeLoc (SourceMgr, File).isInvalid ();
1844
1867
Entry.IsModuleMap = isModuleMap (File.getFileCharacteristic ());
1845
1868
1846
- uint64_t ContentHash = 0 ;
1847
- if (PP->getHeaderSearchInfo ()
1848
- .getHeaderSearchOpts ()
1849
- .ValidateASTInputFilesContent ) {
1850
- auto MemBuff = Cache->getBufferIfLoaded ();
1851
- if (MemBuff)
1852
- ContentHash = xxh3_64bits (MemBuff->getBuffer ());
1853
- else
1854
- PP->Diag (SourceLocation (), diag::err_module_unable_to_hash_content)
1855
- << Entry.File .getName ();
1856
- }
1857
- Entry.ContentHash [0 ] = uint32_t (ContentHash);
1858
- Entry.ContentHash [1 ] = uint32_t (ContentHash >> 32 );
1869
+ Entry.trySetContentHash (*PP, [&] { return Cache->getBufferIfLoaded (); });
1870
+
1859
1871
if (Entry.IsSystemFile )
1860
1872
SystemFiles.push_back (Entry);
1861
1873
else
1862
1874
UserFiles.push_back (Entry);
1863
1875
}
1864
1876
1877
+ // FIXME: Make providing input files not in the SourceManager more flexible.
1878
+ // The SDKSettings.json file is necessary for correct evaluation of
1879
+ // availability annotations.
1880
+ StringRef Sysroot = PP->getHeaderSearchInfo ().getHeaderSearchOpts ().Sysroot ;
1881
+ if (!Sysroot.empty ()) {
1882
+ SmallString<128 > SDKSettingsJSON = Sysroot;
1883
+ llvm::sys::path::append (SDKSettingsJSON, " SDKSettings.json" );
1884
+ FileManager &FM = PP->getFileManager ();
1885
+ if (auto FE = FM.getOptionalFileRef (SDKSettingsJSON)) {
1886
+ InputFileEntry Entry (*FE);
1887
+ Entry.IsSystemFile = true ;
1888
+ Entry.IsTransient = false ;
1889
+ Entry.BufferOverridden = false ;
1890
+ Entry.IsTopLevel = true ;
1891
+ Entry.IsModuleMap = false ;
1892
+ std::unique_ptr<MemoryBuffer> MB;
1893
+ Entry.trySetContentHash (*PP, [&]() -> std::optional<MemoryBufferRef> {
1894
+ if (auto MBOrErr = FM.getBufferForFile (Entry.File )) {
1895
+ MB = std::move (*MBOrErr);
1896
+ return MB->getMemBufferRef ();
1897
+ }
1898
+ return std::nullopt;
1899
+ });
1900
+ SystemFiles.push_back (Entry);
1901
+ }
1902
+ }
1903
+
1865
1904
// User files go at the front, system files at the back.
1866
1905
auto SortedFiles = llvm::concat<InputFileEntry>(std::move (UserFiles),
1867
1906
std::move (SystemFiles));
0 commit comments