Index: include/clang/Serialization/ModuleManager.h =================================================================== --- include/clang/Serialization/ModuleManager.h +++ include/clang/Serialization/ModuleManager.h @@ -34,7 +34,7 @@ SmallVector Chain; /// \brief All loaded modules, indexed by name. - llvm::DenseMap Modules; + llvm::DenseMap> Modules; /// \brief FileManager that handles translating between filenames and /// FileEntry *. Index: lib/Serialization/ModuleManager.cpp =================================================================== --- lib/Serialization/ModuleManager.cpp +++ lib/Serialization/ModuleManager.cpp @@ -37,12 +37,11 @@ } ModuleFile *ModuleManager::lookup(const FileEntry *File) { - llvm::DenseMap::iterator Known - = Modules.find(File); + auto Known = Modules.find(File); if (Known == Modules.end()) return nullptr; - return Known->second; + return Known->second.get(); } std::unique_ptr @@ -78,18 +77,18 @@ } // Check whether we already loaded this module, before - ModuleFile *&ModuleEntry = Modules[Entry]; + std::unique_ptr &ModuleEntry = Modules[Entry]; bool NewModule = false; if (!ModuleEntry) { // Allocate a new module. - ModuleFile *New = new ModuleFile(Type, Generation); + ModuleEntry = llvm::make_unique(Type, Generation); + ModuleFile *New = ModuleEntry.get(); New->Index = Chain.size(); New->FileName = FileName.str(); New->File = Entry; New->ImportLoc = ImportLoc; Chain.push_back(New); NewModule = true; - ModuleEntry = New; New->InputFilesValidationTimestamp = 0; if (New->Kind == MK_ImplicitModule) { @@ -145,7 +144,6 @@ // module is *itself* up to date, but has an out-of-date importer. Modules.erase(Entry); Chain.pop_back(); - delete New; return OutOfDate; } } @@ -153,7 +151,7 @@ if (ImportedBy) { ModuleEntry->ImportedBy.insert(ImportedBy); - ImportedBy->Imports.insert(ModuleEntry); + ImportedBy->Imports.insert(ModuleEntry.get()); } else { if (!ModuleEntry->DirectlyImported) ModuleEntry->ImportLoc = ImportLoc; @@ -161,8 +159,8 @@ ModuleEntry->DirectlyImported = true; } - Module = ModuleEntry; - return NewModule? NewlyLoaded : AlreadyLoaded; + Module = ModuleEntry.get(); + return NewModule ? NewlyLoaded : AlreadyLoaded; } void ModuleManager::removeModules( @@ -184,8 +182,6 @@ // Delete the modules and erase them from the various structures. for (ModuleIterator victim = first; victim != last; ++victim) { - Modules.erase((*victim)->File); - if (modMap) { StringRef ModuleName = (*victim)->ModuleName; if (Module *mod = modMap->findModule(ModuleName)) { @@ -199,7 +195,7 @@ if (LoadedSuccessfully.count(*victim) == 0) FileMgr.invalidateCache((*victim)->File); - delete *victim; + Modules.erase((*victim)->File); } // Remove the modules from the chain. @@ -261,8 +257,6 @@ : FileMgr(FileMgr), GlobalIndex(), FirstVisitState(nullptr) {} ModuleManager::~ModuleManager() { - for (unsigned i = 0, e = Chain.size(); i != e; ++i) - delete Chain[e - i - 1]; delete FirstVisitState; }