diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -1838,7 +1838,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. diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -385,10 +385,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) @@ -414,7 +412,7 @@ Entry->IsFileVolatile = UserFilesAreVolatile && !isSystemFile; Entry->IsTransient = FilesAreTransient; - Entry->BufferOverridden |= FileEnt->isNamedPipe(); + Entry->BufferOverridden |= FileEnt.isNamedPipe(); return *Entry; } @@ -542,7 +540,7 @@ SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID, unsigned LoadedOffset) { - SrcMgr::ContentCache &IR = getOrCreateContentCache(&SourceFile.getFileEntry(), + SrcMgr::ContentCache &IR = getOrCreateContentCache(SourceFile, isSystem(FileCharacter)); // If this is a named pipe, immediately load the buffer to ensure subsequent @@ -682,13 +680,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; @@ -716,12 +714,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 diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp --- a/clang/lib/Serialization/ASTReader.cpp +++ b/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 @@ -1515,9 +1515,8 @@ } SrcMgr::CharacteristicKind FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; - // FIXME: The FileID should be created from the FileEntryRef. - FileID FID = SourceMgr.createFileID(File, IncludeLoc, FileCharacter, - ID, BaseOffset + Record[0]); + FileID FID = SourceMgr.createFileID(*File, IncludeLoc, FileCharacter, ID, + BaseOffset + Record[0]); SrcMgr::FileInfo &FileInfo = const_cast(SourceMgr.getSLocEntry(FID).getFile()); FileInfo.NumCreatedFIDs = Record[5]; @@ -1533,14 +1532,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;