@@ -1774,6 +1774,29 @@ struct InputFileEntry {
17741774 uint32_t ContentHash[2 ];
17751775
17761776 InputFileEntry (FileEntryRef File) : File(File) {}
1777+
1778+ void trySetContentHash (
1779+ Preprocessor &PP,
1780+ llvm::function_ref<std::optional<llvm::MemoryBufferRef>()> GetMemBuff) {
1781+ ContentHash[0 ] = 0 ;
1782+ ContentHash[1 ] = 0 ;
1783+
1784+ if (!PP.getHeaderSearchInfo ()
1785+ .getHeaderSearchOpts ()
1786+ .ValidateASTInputFilesContent )
1787+ return ;
1788+
1789+ auto MemBuff = GetMemBuff ();
1790+ if (!MemBuff) {
1791+ PP.Diag (SourceLocation (), diag::err_module_unable_to_hash_content)
1792+ << File.getName ();
1793+ return ;
1794+ }
1795+
1796+ uint64_t Hash = xxh3_64bits (MemBuff->getBuffer ());
1797+ ContentHash[0 ] = uint32_t (Hash);
1798+ ContentHash[1 ] = uint32_t (Hash >> 32 );
1799+ }
17771800};
17781801
17791802} // namespace
@@ -1848,25 +1871,41 @@ void ASTWriter::WriteInputFiles(SourceManager &SourceMgr) {
18481871 !IsSLocFileEntryAffecting[IncludeFileID.ID ];
18491872 Entry.IsModuleMap = isModuleMap (File.getFileCharacteristic ());
18501873
1851- uint64_t ContentHash = 0 ;
1852- if (PP->getHeaderSearchInfo ()
1853- .getHeaderSearchOpts ()
1854- .ValidateASTInputFilesContent ) {
1855- auto MemBuff = Cache->getBufferIfLoaded ();
1856- if (MemBuff)
1857- ContentHash = xxh3_64bits (MemBuff->getBuffer ());
1858- else
1859- PP->Diag (SourceLocation (), diag::err_module_unable_to_hash_content)
1860- << Entry.File .getName ();
1861- }
1862- Entry.ContentHash [0 ] = uint32_t (ContentHash);
1863- Entry.ContentHash [1 ] = uint32_t (ContentHash >> 32 );
1874+ Entry.trySetContentHash (*PP, [&] { return Cache->getBufferIfLoaded (); });
1875+
18641876 if (Entry.IsSystemFile )
18651877 SystemFiles.push_back (Entry);
18661878 else
18671879 UserFiles.push_back (Entry);
18681880 }
18691881
1882+ // FIXME: Make providing input files not in the SourceManager more flexible.
1883+ // The SDKSettings.json file is necessary for correct evaluation of
1884+ // availability annotations.
1885+ StringRef Sysroot = PP->getHeaderSearchInfo ().getHeaderSearchOpts ().Sysroot ;
1886+ if (!Sysroot.empty ()) {
1887+ SmallString<128 > SDKSettingsJSON = Sysroot;
1888+ llvm::sys::path::append (SDKSettingsJSON, " SDKSettings.json" );
1889+ FileManager &FM = PP->getFileManager ();
1890+ if (auto FE = FM.getOptionalFileRef (SDKSettingsJSON)) {
1891+ InputFileEntry Entry (*FE);
1892+ Entry.IsSystemFile = true ;
1893+ Entry.IsTransient = false ;
1894+ Entry.BufferOverridden = false ;
1895+ Entry.IsTopLevel = true ;
1896+ Entry.IsModuleMap = false ;
1897+ std::unique_ptr<MemoryBuffer> MB;
1898+ Entry.trySetContentHash (*PP, [&]() -> std::optional<MemoryBufferRef> {
1899+ if (auto MBOrErr = FM.getBufferForFile (Entry.File )) {
1900+ MB = std::move (*MBOrErr);
1901+ return MB->getMemBufferRef ();
1902+ }
1903+ return std::nullopt ;
1904+ });
1905+ SystemFiles.push_back (Entry);
1906+ }
1907+ }
1908+
18701909 // User files go at the front, system files at the back.
18711910 auto SortedFiles = llvm::concat<InputFileEntry>(std::move (UserFiles),
18721911 std::move (SystemFiles));
0 commit comments