Skip to content
Snippets Groups Projects
Commit d7d0010c authored by Ben Langmuir's avatar Ben Langmuir
Browse files

Invalidate the file system cache entries for files that may rebuild

I thought we could get away without this, but it means that the
FileEntry objects actually refer to the wrong files, since pcms are not
updated inplace, they are atomically renamed into place after compiling
a module.

So we are close to the original behaviour of invalidating the cache for
all modules being removed, but now we should only invalidate the ones
that depend on whichever module failed to load.

Unfortunately I haven't come up with a new test that didn't require
a race between parallel invocations of clang.

<rdar://problem/17038180>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209910 91177308-0d34-0410-b5e6-96231b3b80d8
parent 6ecc8861
No related branches found
No related tags found
No related merge requests found
......@@ -135,19 +135,32 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
return NewModule? NewlyLoaded : AlreadyLoaded;
}
static void invalidateFileCacheForFileAndImporters(
ModuleFile *F, FileManager &FileMgr,
llvm::SmallPtrSetImpl<ModuleFile *> &VictimSet) {
assert(VictimSet.count(F) && "removeModules() missing ancestor of module "
"that failed to load");
FileMgr.invalidateCache(F->File);
F->File = nullptr;
for (ModuleFile *Importer : F->ImportedBy)
invalidateFileCacheForFileAndImporters(Importer, FileMgr, VictimSet);
}
void ModuleManager::removeModules(ModuleIterator first, ModuleIterator last,
ModuleMap *modMap) {
if (first == last)
return;
// The first file entry is about to be rebuilt (or there was an error), so
// there should be no references to it. Remove it from the cache to close it,
// as Windows doesn't seem to allow renaming over an open file.
FileMgr.invalidateCache((*first)->File);
// Collect the set of module file pointers that we'll be removing.
llvm::SmallPtrSet<ModuleFile *, 4> victimSet(first, last);
// The last module file caused the load failure, so it and its ancestors in
// the module dependency tree will be rebuilt (or there was an error), so
// there should be no references to them. Remove them from the cache,
// since rebuilding them will create new files at the old locations.
invalidateFileCacheForFileAndImporters(*(last-1), FileMgr, victimSet);
assert((*first)->File == nullptr && "non-dependent module loaded");
// Remove any references to the now-destroyed modules.
for (unsigned i = 0, n = Chain.size(); i != n; ++i) {
Chain[i]->ImportedBy.remove_if([&](ModuleFile *MF) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment