Index: clang/include/clang/Basic/SourceManager.h =================================================================== --- clang/include/clang/Basic/SourceManager.h +++ clang/include/clang/Basic/SourceManager.h @@ -1840,7 +1840,7 @@ SrcMgr::CharacteristicKind DirCharacter, int LoadedID, unsigned LoadedOffset); - SrcMgr::ContentCache &getOrCreateContentCache(const FileEntry *SourceFile, + SrcMgr::ContentCache &getOrCreateContentCache(FileEntryRef SourceFile, bool isSystemFile = false); /// Create a new ContentCache for the specified memory buffer. Index: clang/lib/Basic/SourceManager.cpp =================================================================== --- clang/lib/Basic/SourceManager.cpp +++ clang/lib/Basic/SourceManager.cpp @@ -380,10 +380,8 @@ } } -ContentCache &SourceManager::getOrCreateContentCache(const FileEntry *FileEnt, +ContentCache &SourceManager::getOrCreateContentCache(FileEntryRef FileEnt, bool isSystemFile) { - assert(FileEnt && "Didn't specify a file entry to use?"); - // Do we already have information about this file? ContentCache *&Entry = FileInfos[FileEnt]; if (Entry) @@ -528,7 +526,7 @@ SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID, unsigned LoadedOffset) { - SrcMgr::ContentCache &IR = getOrCreateContentCache(&SourceFile.getFileEntry(), + SrcMgr::ContentCache &IR = getOrCreateContentCache(SourceFile, isSystem(FileCharacter)); return createFileIDImpl(IR, SourceFile.getName(), IncludePos, FileCharacter, LoadedID, LoadedOffset); @@ -662,13 +660,13 @@ llvm::Optional SourceManager::getMemoryBufferForFileOrNone(const FileEntry *File) { - SrcMgr::ContentCache &IR = getOrCreateContentCache(File); + SrcMgr::ContentCache &IR = getOrCreateContentCache(File->getLastRef()); return IR.getBufferOrNone(Diag, getFileManager(), SourceLocation()); } void SourceManager::overrideFileContents( const FileEntry *SourceFile, std::unique_ptr Buffer) { - SrcMgr::ContentCache &IR = getOrCreateContentCache(SourceFile); + SrcMgr::ContentCache &IR = getOrCreateContentCache(SourceFile->getLastRef()); IR.setBuffer(std::move(Buffer)); IR.BufferOverridden = true; @@ -696,12 +694,12 @@ if (!BypassFile) return None; - (void)getOrCreateContentCache(&BypassFile->getFileEntry()); + (void)getOrCreateContentCache(*BypassFile); return BypassFile; } void SourceManager::setFileIsTransient(const FileEntry *File) { - getOrCreateContentCache(File).IsTransient = true; + getOrCreateContentCache(File->getLastRef()).IsTransient = true; } Optional Index: clang/lib/Serialization/ASTReader.cpp =================================================================== --- clang/lib/Serialization/ASTReader.cpp +++ clang/lib/Serialization/ASTReader.cpp @@ -1499,7 +1499,7 @@ // we will also try to fail gracefully by setting up the SLocEntry. unsigned InputID = Record[4]; InputFile IF = getInputFile(*F, InputID); - const FileEntry *File = IF.getFile(); + Optional File = IF.getFile(); bool OverriddenBuffer = IF.isOverridden(); // Note that we only check if a File was returned. If it was out-of-date @@ -1516,7 +1516,7 @@ SrcMgr::CharacteristicKind FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; // FIXME: The FileID should be created from the FileEntryRef. - FileID FID = SourceMgr.createFileID(File, IncludeLoc, FileCharacter, + FileID FID = SourceMgr.createFileID(*File, IncludeLoc, FileCharacter, ID, BaseOffset + Record[0]); SrcMgr::FileInfo &FileInfo = const_cast(SourceMgr.getSLocEntry(FID).getFile()); @@ -1533,14 +1533,14 @@ } const SrcMgr::ContentCache &ContentCache = - SourceMgr.getOrCreateContentCache(File, isSystem(FileCharacter)); + SourceMgr.getOrCreateContentCache(*File, isSystem(FileCharacter)); if (OverriddenBuffer && !ContentCache.BufferOverridden && ContentCache.ContentsEntry == ContentCache.OrigEntry && !ContentCache.getBufferIfLoaded()) { auto Buffer = ReadBuffer(SLocEntryCursor, File->getName()); if (!Buffer) return true; - SourceMgr.overrideFileContents(File, std::move(Buffer)); + SourceMgr.overrideFileContents(*File, std::move(Buffer)); } break;