From 1f062cda84f537547021640c8bcd9c589c418d96 Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Mon, 10 Oct 2016 16:26:08 +0000 Subject: [PATCH] [Sema] Use unique_ptr instead of raw pointers in the late-parsed templates map. Summary: This is possible now that MapVector supports move-only values. Depends on D25404. Reviewers: timshen Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25405 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283766 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/ExternalSemaSource.h | 3 ++- include/clang/Sema/MultiplexExternalSemaSource.h | 4 ++-- include/clang/Sema/Sema.h | 3 ++- include/clang/Serialization/ASTReader.h | 4 ++-- lib/Sema/MultiplexExternalSemaSource.cpp | 3 ++- lib/Sema/Sema.cpp | 1 - lib/Sema/SemaTemplate.cpp | 4 ++-- lib/Sema/SemaTemplateInstantiateDecl.cpp | 7 ++++--- lib/Serialization/ASTReader.cpp | 7 ++++--- lib/Serialization/ASTWriter.cpp | 10 +++++----- 10 files changed, 25 insertions(+), 21 deletions(-) diff --git a/include/clang/Sema/ExternalSemaSource.h b/include/clang/Sema/ExternalSemaSource.h index c2b13046d7..c5cb7b12b3 100644 --- a/include/clang/Sema/ExternalSemaSource.h +++ b/include/clang/Sema/ExternalSemaSource.h @@ -190,7 +190,8 @@ public: /// external source should take care not to introduce the same map entries /// repeatedly. virtual void ReadLateParsedTemplates( - llvm::MapVector &LPTMap) {} + llvm::MapVector> + &LPTMap) {} /// \copydoc Sema::CorrectTypo /// \note LookupKind must correspond to a valid Sema::LookupNameKind diff --git a/include/clang/Sema/MultiplexExternalSemaSource.h b/include/clang/Sema/MultiplexExternalSemaSource.h index 9bf8cd3d92..37157204ea 100644 --- a/include/clang/Sema/MultiplexExternalSemaSource.h +++ b/include/clang/Sema/MultiplexExternalSemaSource.h @@ -322,8 +322,8 @@ public: /// external source should take care not to introduce the same map entries /// repeatedly. void ReadLateParsedTemplates( - llvm::MapVector &LPTMap) - override; + llvm::MapVector> + &LPTMap) override; /// \copydoc ExternalSemaSource::CorrectTypo /// \note Returns the first nonempty correction. diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 8bd3916e0d..1517160180 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -551,7 +551,8 @@ public: SmallVector, 2> DelayedDefaultedMemberExceptionSpecs; - typedef llvm::MapVector + typedef llvm::MapVector> LateParsedTemplateMapT; LateParsedTemplateMapT LateParsedTemplateMap; diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 066cb4d9de..49dad3e135 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -1877,8 +1877,8 @@ public: SourceLocation> > &Pending) override; void ReadLateParsedTemplates( - llvm::MapVector &LPTMap) - override; + llvm::MapVector> + &LPTMap) override; /// \brief Load a selector from disk, registering its ID if it exists. void LoadSelector(Selector Sel); diff --git a/lib/Sema/MultiplexExternalSemaSource.cpp b/lib/Sema/MultiplexExternalSemaSource.cpp index eee4c00324..077a56ff8e 100644 --- a/lib/Sema/MultiplexExternalSemaSource.cpp +++ b/lib/Sema/MultiplexExternalSemaSource.cpp @@ -285,7 +285,8 @@ void MultiplexExternalSemaSource::ReadPendingInstantiations( } void MultiplexExternalSemaSource::ReadLateParsedTemplates( - llvm::MapVector &LPTMap) { + llvm::MapVector> + &LPTMap) { for (size_t i = 0; i < Sources.size(); ++i) Sources[i]->ReadLateParsedTemplates(LPTMap); } diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 9ea5cba94e..fac608de6f 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -259,7 +259,6 @@ void Sema::Initialize() { } Sema::~Sema() { - llvm::DeleteContainerSeconds(LateParsedTemplateMap); if (VisContext) FreeVisContext(); // Kill all the active scopes. for (unsigned I = 1, E = FunctionScopes.size(); I != E; ++I) diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 7061f079ac..0a03f8efc1 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -8668,12 +8668,12 @@ void Sema::MarkAsLateParsedTemplate(FunctionDecl *FD, Decl *FnD, if (!FD) return; - LateParsedTemplate *LPT = new LateParsedTemplate; + auto LPT = llvm::make_unique(); // Take tokens to avoid allocations LPT->Toks.swap(Toks); LPT->D = FnD; - LateParsedTemplateMap.insert(std::make_pair(FD, LPT)); + LateParsedTemplateMap.insert(std::make_pair(FD, std::move(LPT))); FD->setLateTemplateParsed(true); } diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index cc8f56b4c5..09068d71ff 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3622,9 +3622,10 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, if (PatternDecl->isFromASTFile()) ExternalSource->ReadLateParsedTemplates(LateParsedTemplateMap); - LateParsedTemplate *LPT = LateParsedTemplateMap.lookup(PatternDecl); - assert(LPT && "missing LateParsedTemplate"); - LateTemplateParser(OpaqueParser, *LPT); + auto LPTIter = LateParsedTemplateMap.find(PatternDecl); + assert(LPTIter != LateParsedTemplateMap.end() && + "missing LateParsedTemplate"); + LateTemplateParser(OpaqueParser, *LPTIter->second); Pattern = PatternDecl->getBody(PatternDecl); } diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index d12dda66db..52e06e482e 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -7556,12 +7556,13 @@ void ASTReader::ReadPendingInstantiations( } void ASTReader::ReadLateParsedTemplates( - llvm::MapVector &LPTMap) { + llvm::MapVector> + &LPTMap) { for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N; /* In loop */) { FunctionDecl *FD = cast(GetDecl(LateParsedTemplates[Idx++])); - LateParsedTemplate *LT = new LateParsedTemplate; + auto LT = llvm::make_unique(); LT->D = GetDecl(LateParsedTemplates[Idx++]); ModuleFile *F = getOwningModuleFile(LT->D); @@ -7572,7 +7573,7 @@ void ASTReader::ReadLateParsedTemplates( for (unsigned T = 0; T < TokN; ++T) LT->Toks.push_back(ReadToken(*F, LateParsedTemplates, Idx)); - LPTMap.insert(std::make_pair(FD, LT)); + LPTMap.insert(std::make_pair(FD, std::move(LT))); } LateParsedTemplates.clear(); diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index da513a7076..335a9320e3 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -4009,14 +4009,14 @@ void ASTWriter::WriteLateParsedTemplates(Sema &SemaRef) { return; RecordData Record; - for (auto LPTMapEntry : LPTMap) { + for (auto &LPTMapEntry : LPTMap) { const FunctionDecl *FD = LPTMapEntry.first; - LateParsedTemplate *LPT = LPTMapEntry.second; + LateParsedTemplate &LPT = *LPTMapEntry.second; AddDeclRef(FD, Record); - AddDeclRef(LPT->D, Record); - Record.push_back(LPT->Toks.size()); + AddDeclRef(LPT.D, Record); + Record.push_back(LPT.Toks.size()); - for (const auto &Tok : LPT->Toks) { + for (const auto &Tok : LPT.Toks) { AddToken(Tok, Record); } } -- 2.40.0