diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp --- a/clang/lib/Serialization/ModuleManager.cpp +++ b/clang/lib/Serialization/ModuleManager.cpp @@ -232,9 +232,15 @@ // Read the signature eagerly now so that we can check it. Avoid calling // ReadSignature unless there's something to check though. if (ExpectedSignature && checkSignature(ReadSignature(NewModule->Data), - ExpectedSignature, ErrorStr)) + ExpectedSignature, ErrorStr)) { + // Try to remove the buffer. If it can't be removed, then it was already + // validated by this process. + if (!getModuleCache().tryToDropPCM(NewModule->FileName)) { + const FileEntry *FE = NewModule->File; + FileMgr.invalidateCache(const_cast(FE)); + } return OutOfDate; - + } // We're keeping this module. Store it everywhere. Module = Modules[Entry] = NewModule.get(); @@ -284,6 +290,8 @@ for (ModuleIterator victim = First; victim != Last; ++victim) { Modules.erase(victim->File); + const FileEntry *FE = victim->File; + FileMgr.invalidateCache(const_cast(FE)); if (modMap) { StringRef ModuleName = victim->ModuleName; if (Module *mod = modMap->findModule(ModuleName)) {