Index: include/clang/Frontend/ASTUnit.h =================================================================== --- include/clang/Frontend/ASTUnit.h +++ include/clang/Frontend/ASTUnit.h @@ -31,6 +31,7 @@ #include "llvm/ADT/StringMap.h" #include "llvm/Support/MD5.h" #include "llvm/Support/Path.h" +#include "llvm/Support/FileSystem.h" #include #include #include @@ -264,12 +265,15 @@ /// a line after skipping the preamble. bool PreambleEndsAtStartOfLine; + typedef std::map> FilesInPreambleMap; + /// \brief Keeps track of the files that were used when computing the /// preamble, with both their buffer size and their modification time. /// /// If any of the files have changed from one compile to the next, /// the preamble must be thrown away. - llvm::StringMap FilesInPreamble; + FilesInPreambleMap FilesInPreamble; /// \brief When non-NULL, this is the buffer used to store the contents of /// the main file when it has been padded for use with the precompiled Index: lib/Frontend/ASTUnit.cpp =================================================================== --- lib/Frontend/ASTUnit.cpp +++ lib/Frontend/ASTUnit.cpp @@ -1378,7 +1378,7 @@ // First, make a record of those files that have been overridden via // remapping or unsaved_files. - llvm::StringMap OverriddenFiles; + std::map OverriddenFiles; for (const auto &R : PreprocessorOpts.RemappedFiles) { if (AnyFileChanged) break; @@ -1391,40 +1391,47 @@ break; } - OverriddenFiles[R.first] = PreambleFileHash::createForFile( + OverriddenFiles[Status.getUniqueID()] = PreambleFileHash::createForFile( Status.getSize(), Status.getLastModificationTime().toEpochTime()); } for (const auto &RB : PreprocessorOpts.RemappedFileBuffers) { if (AnyFileChanged) break; - OverriddenFiles[RB.first] = + + vfs::Status Status; + if (FileMgr->getNoncachedStatValue(RB.first, Status)) { + AnyFileChanged = true; + break; + } + + OverriddenFiles[Status.getUniqueID()] = PreambleFileHash::createForMemoryBuffer(RB.second); } // Check whether anything has changed. - for (llvm::StringMap::iterator + for (FilesInPreambleMap::iterator F = FilesInPreamble.begin(), FEnd = FilesInPreamble.end(); !AnyFileChanged && F != FEnd; ++F) { - llvm::StringMap::iterator Overridden - = OverriddenFiles.find(F->first()); + std::map::iterator Overridden + = OverriddenFiles.find(F->first); if (Overridden != OverriddenFiles.end()) { // This file was remapped; check whether the newly-mapped file // matches up with the previous mapping. - if (Overridden->second != F->second) + if (Overridden->second != F->second.second) AnyFileChanged = true; continue; } // The file was not remapped; check whether it has changed on disk. vfs::Status Status; - if (FileMgr->getNoncachedStatValue(F->first(), Status)) { + if (FileMgr->getNoncachedStatValue(F->second.first, Status)) { // If we can't stat the file, assume that something horrible happened. AnyFileChanged = true; - } else if (Status.getSize() != uint64_t(F->second.Size) || + } else if (Status.getSize() != uint64_t(F->second.second.Size) || Status.getLastModificationTime().toEpochTime() != - uint64_t(F->second.ModTime)) + uint64_t(F->second.second.ModTime)) AnyFileChanged = true; } @@ -1612,12 +1619,14 @@ if (!File || File == SourceMgr.getFileEntryForID(SourceMgr.getMainFileID())) continue; if (time_t ModTime = File->getModificationTime()) { - FilesInPreamble[File->getName()] = PreambleFileHash::createForFile( - File->getSize(), ModTime); + FilesInPreamble[File->getUniqueID()] = std::make_pair( + File->getName(), + PreambleFileHash::createForFile(File->getSize(), ModTime)); } else { llvm::MemoryBuffer *Buffer = SourceMgr.getMemoryBufferForFile(File); - FilesInPreamble[File->getName()] = - PreambleFileHash::createForMemoryBuffer(Buffer); + FilesInPreamble[File->getUniqueID()] = std::make_pair( + File->getName(), + PreambleFileHash::createForMemoryBuffer(Buffer)); } }