diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2015-03-26 09:08:15 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2015-03-26 09:08:15 +0000 |
commit | 52cee4dad2de9bed6f552b74391f20c84aee3622 (patch) | |
tree | e7e9bb35da701f6180968505cda2fe1a6383fb69 /clang/lib | |
parent | 70a1369b342e2c3cd39cef7ec70d9115ca63483c (diff) | |
download | llvm-52cee4dad2de9bed6f552b74391f20c84aee3622.zip llvm-52cee4dad2de9bed6f552b74391f20c84aee3622.tar.gz llvm-52cee4dad2de9bed6f552b74391f20c84aee3622.tar.bz2 |
[Modules] Preserve source order for the map of late parsed templates.
Clang was inserting these into a dense map. While it never iterated the
dense map during normal compilation, it did when emitting a module. Fix
this by using a standard MapVector to preserve the order in which we
encounter the late parsed templates.
I suspect this still isn't ideal, as we don't seem to remove things from
this map even when we mark the templates as no longer late parsed. But
I don't know enough about this particular extension to craft a nice,
subtle test case covering this. I've managed to get the stress test to
at least do some late parsing and demonstrate the core problem here.
This patch fixes the test and provides deterministic behavior which is
a strict improvement over the prior state.
I've cleaned up some of the code here as well to be explicit about
inserting when that is what is actually going on.
llvm-svn: 233264
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Sema/MultiplexExternalSemaSource.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplate.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTWriter.cpp | 9 |
4 files changed, 8 insertions, 9 deletions
diff --git a/clang/lib/Sema/MultiplexExternalSemaSource.cpp b/clang/lib/Sema/MultiplexExternalSemaSource.cpp index bd7e785..51a1274 100644 --- a/clang/lib/Sema/MultiplexExternalSemaSource.cpp +++ b/clang/lib/Sema/MultiplexExternalSemaSource.cpp @@ -276,7 +276,7 @@ void MultiplexExternalSemaSource::ReadPendingInstantiations( } void MultiplexExternalSemaSource::ReadLateParsedTemplates( - llvm::DenseMap<const FunctionDecl *, LateParsedTemplate *> &LPTMap) { + llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap) { for (size_t i = 0; i < Sources.size(); ++i) Sources[i]->ReadLateParsedTemplates(LPTMap); } diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index fad15bb..805709d 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -8305,7 +8305,7 @@ void Sema::MarkAsLateParsedTemplate(FunctionDecl *FD, Decl *FnD, // Take tokens to avoid allocations LPT->Toks.swap(Toks); LPT->D = FnD; - LateParsedTemplateMap[FD] = LPT; + LateParsedTemplateMap.insert(std::make_pair(FD, LPT)); FD->setLateTemplateParsed(true); } diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 2273979..4d5141b 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -7453,7 +7453,7 @@ void ASTReader::ReadPendingInstantiations( } void ASTReader::ReadLateParsedTemplates( - llvm::DenseMap<const FunctionDecl *, LateParsedTemplate *> &LPTMap) { + llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap) { for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N; /* In loop */) { FunctionDecl *FD = cast<FunctionDecl>(GetDecl(LateParsedTemplates[Idx++])); @@ -7469,7 +7469,7 @@ void ASTReader::ReadLateParsedTemplates( for (unsigned T = 0; T < TokN; ++T) LT->Toks.push_back(ReadToken(*F, LateParsedTemplates, Idx)); - LPTMap[FD] = LT; + LPTMap.insert(std::make_pair(FD, LT)); } LateParsedTemplates.clear(); diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 7227a97..679419c 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -4089,11 +4089,10 @@ void ASTWriter::WriteLateParsedTemplates(Sema &SemaRef) { return; RecordData Record; - for (Sema::LateParsedTemplateMapT::iterator It = LPTMap.begin(), - ItEnd = LPTMap.end(); - It != ItEnd; ++It) { - LateParsedTemplate *LPT = It->second; - AddDeclRef(It->first, Record); + for (auto LPTMapEntry : LPTMap) { + const FunctionDecl *FD = LPTMapEntry.first; + LateParsedTemplate *LPT = LPTMapEntry.second; + AddDeclRef(FD, Record); AddDeclRef(LPT->D, Record); Record.push_back(LPT->Toks.size()); |