diff options
Diffstat (limited to 'clang/lib/Serialization/ASTReader.cpp')
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index fa84b94b082..2defd38e27a 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -1259,7 +1259,8 @@ bool ASTReader::ReadSLocEntry(int ID) { = SourceMgr.getOrCreateContentCache(File, /*isSystemFile=*/FileCharacter != SrcMgr::C_User); if (OverriddenBuffer && !ContentCache->BufferOverridden && - ContentCache->ContentsEntry == ContentCache->OrigEntry) { + ContentCache->ContentsEntry == ContentCache->OrigEntry && + !ContentCache->getRawBuffer()) { unsigned Code = SLocEntryCursor.ReadCode(); Record.clear(); unsigned RecCode = SLocEntryCursor.readRecord(Code, Record, &Blob); @@ -1890,19 +1891,14 @@ ASTReader::readInputFileInfo(ModuleFile &F, unsigned ID) { "invalid record type for input file"); (void)Result; - std::string Filename; - off_t StoredSize; - time_t StoredTime; - bool Overridden; - assert(Record[0] == ID && "Bogus stored ID or offset"); - StoredSize = static_cast<off_t>(Record[1]); - StoredTime = static_cast<time_t>(Record[2]); - Overridden = static_cast<bool>(Record[3]); - Filename = Blob; - ResolveImportedPath(F, Filename); - - InputFileInfo R = { std::move(Filename), StoredSize, StoredTime, Overridden }; + InputFileInfo R; + R.StoredSize = static_cast<off_t>(Record[1]); + R.StoredTime = static_cast<time_t>(Record[2]); + R.Overridden = static_cast<bool>(Record[3]); + R.Transient = static_cast<bool>(Record[4]); + R.Filename = Blob; + ResolveImportedPath(F, R.Filename); return R; } @@ -1927,11 +1923,10 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { off_t StoredSize = FI.StoredSize; time_t StoredTime = FI.StoredTime; bool Overridden = FI.Overridden; + bool Transient = FI.Transient; StringRef Filename = FI.Filename; - const FileEntry *File - = Overridden? FileMgr.getVirtualFile(Filename, StoredSize, StoredTime) - : FileMgr.getFile(Filename, /*OpenFile=*/false); + const FileEntry *File = FileMgr.getFile(Filename, /*OpenFile=*/false); // If we didn't find the file, resolve it relative to the // original directory from which this AST file was created. @@ -1946,9 +1941,8 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { // For an overridden file, create a virtual file with the stored // size/timestamp. - if (Overridden && File == nullptr) { + if ((Overridden || Transient) && File == nullptr) File = FileMgr.getVirtualFile(Filename, StoredSize, StoredTime); - } if (File == nullptr) { if (Complain) { @@ -1974,6 +1968,11 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { Error(diag::err_fe_pch_file_overridden, Filename); // After emitting the diagnostic, recover by disabling the override so // that the original file will be used. + // + // FIXME: This recovery is just as broken as the original state; there may + // be another precompiled module that's using the overridden contents, or + // we might be half way through parsing it. Instead, we should treat the + // overridden contents as belonging to a separate FileEntry. SM.disableFileContentsOverride(File); // The FileEntry is a virtual file entry with the size of the contents // that would override the original contents. Set it to the original's @@ -2024,8 +2023,10 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { IsOutOfDate = true; } + // FIXME: If the file is overridden and we've already opened it, + // issue an error (or split it into a separate FileEntry). - InputFile IF = InputFile(File, Overridden, IsOutOfDate); + InputFile IF = InputFile(File, Overridden || Transient, IsOutOfDate); // Note that we've loaded this input file. F.InputFilesLoaded[ID-1] = IF; |