Index: include/clang/Lex/HeaderMap.h =================================================================== --- include/clang/Lex/HeaderMap.h +++ include/clang/Lex/HeaderMap.h @@ -71,7 +71,8 @@ public: /// This attempts to load the specified file as a header map. If it doesn't /// look like a HeaderMap, it gives up and returns null. - static const HeaderMap *Create(const FileEntry *FE, FileManager &FM); + static std::unique_ptr Create(const FileEntry *FE, + FileManager &FM); /// Check to see if the specified relative filename is located in this /// HeaderMap. If so, open it and return its FileEntry. If RawPath is not Index: include/clang/Lex/HeaderSearch.h =================================================================== --- include/clang/Lex/HeaderSearch.h +++ include/clang/Lex/HeaderSearch.h @@ -17,6 +17,7 @@ #include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "clang/Lex/DirectoryLookup.h" +#include "clang/Lex/HeaderMap.h" #include "clang/Lex/ModuleMap.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" @@ -38,7 +39,6 @@ class ExternalPreprocessorSource; class FileEntry; class FileManager; -class HeaderMap; class HeaderSearchOptions; class IdentifierInfo; class LangOptions; @@ -226,9 +226,8 @@ llvm::StringMap; std::unique_ptr IncludeAliases; - /// HeaderMaps - This is a mapping from FileEntry -> HeaderMap, uniquing - /// headermaps. This vector owns the headermap. - std::vector> HeaderMaps; + /// This is a mapping from FileEntry -> HeaderMap, uniquing headermaps. + std::vector>> HeaderMaps; /// The mapping between modules and headers. mutable ModuleMap ModMap; @@ -264,7 +263,6 @@ const LangOptions &LangOpts, const TargetInfo *Target); HeaderSearch(const HeaderSearch &) = delete; HeaderSearch &operator=(const HeaderSearch &) = delete; - ~HeaderSearch(); /// Retrieve the header-search options with which this header search /// was initialized. Index: lib/Lex/HeaderMap.cpp =================================================================== --- lib/Lex/HeaderMap.cpp +++ lib/Lex/HeaderMap.cpp @@ -48,7 +48,8 @@ /// map. If it doesn't look like a HeaderMap, it gives up and returns null. /// If it looks like a HeaderMap but is obviously corrupted, it puts a reason /// into the string error argument and returns null. -const HeaderMap *HeaderMap::Create(const FileEntry *FE, FileManager &FM) { +std::unique_ptr HeaderMap::Create(const FileEntry *FE, + FileManager &FM) { // If the file is too small to be a header map, ignore it. unsigned FileSize = FE->getSize(); if (FileSize <= sizeof(HMapHeader)) return nullptr; @@ -59,7 +60,7 @@ bool NeedsByteSwap; if (!checkHeader(**FileBuffer, NeedsByteSwap)) return nullptr; - return new HeaderMap(std::move(*FileBuffer), NeedsByteSwap); + return std::unique_ptr(new HeaderMap(std::move(*FileBuffer), NeedsByteSwap)); } bool HeaderMapImpl::checkHeader(const llvm::MemoryBuffer &File, Index: lib/Lex/HeaderSearch.cpp =================================================================== --- lib/Lex/HeaderSearch.cpp +++ lib/Lex/HeaderSearch.cpp @@ -75,12 +75,6 @@ FileMgr(SourceMgr.getFileManager()), FrameworkMap(64), ModMap(SourceMgr, Diags, LangOpts, Target, *this) {} -HeaderSearch::~HeaderSearch() { - // Delete headermaps. - for (unsigned i = 0, e = HeaderMaps.size(); i != e; ++i) - delete HeaderMaps[i].second; -} - void HeaderSearch::PrintStats() { fprintf(stderr, "\n*** HeaderSearch Stats:\n"); fprintf(stderr, "%d files tracked.\n", (int)FileInfo.size()); @@ -113,12 +107,12 @@ // Pointer equality comparison of FileEntries works because they are // already uniqued by inode. if (HeaderMaps[i].first == FE) - return HeaderMaps[i].second; + return HeaderMaps[i].second.get(); } - if (const HeaderMap *HM = HeaderMap::Create(FE, FileMgr)) { - HeaderMaps.push_back(std::make_pair(FE, HM)); - return HM; + if (std::unique_ptr HM = HeaderMap::Create(FE, FileMgr)) { + HeaderMaps.emplace_back(FE, std::move(HM)); + return HeaderMaps.back().second.get(); } return nullptr;