Replace UsingDecl's SmallPtrSet of UsingShadowDecls with a linked list to avoid leaking memory.
Fixes rdar://8649963.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118674 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp
index 4fca092..e494470 100644
--- a/lib/Serialization/ASTReaderDecl.cpp
+++ b/lib/Serialization/ASTReaderDecl.cpp
@@ -717,16 +717,7 @@
D->setNestedNameRange(ReadSourceRange(Record, Idx));
D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx);
-
- // FIXME: It would probably be more efficient to read these into a vector
- // and then re-cosntruct the shadow decl set over that vector since it
- // would avoid existence checks.
- unsigned NumShadows = Record[Idx++];
- for(unsigned I = 0; I != NumShadows; ++I) {
- // Avoid invariant checking of UsingDecl::addShadowDecl, the decl may still
- // be initializing.
- D->Shadows.insert(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
- }
+ D->FirstUsingShadow = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
D->setTypeName(Record[Idx++]);
NamedDecl *Pattern = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
if (Pattern)
@@ -736,7 +727,7 @@
void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
VisitNamedDecl(D);
D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
- D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
+ D->UsingOrNextShadow = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
UsingShadowDecl *Pattern
= cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
if (Pattern)
diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp
index de58cd0..609a044 100644
--- a/lib/Serialization/ASTWriterDecl.cpp
+++ b/lib/Serialization/ASTWriterDecl.cpp
@@ -673,10 +673,7 @@
Writer.AddSourceLocation(D->getUsingLocation(), Record);
Writer.AddNestedNameSpecifier(D->getTargetNestedNameDecl(), Record);
Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
- Record.push_back(D->getNumShadowDecls());
- for (UsingDecl::shadow_iterator P = D->shadow_begin(),
- PEnd = D->shadow_end(); P != PEnd; ++P)
- Writer.AddDeclRef(*P, Record);
+ Writer.AddDeclRef(D->FirstUsingShadow, Record);
Record.push_back(D->isTypeName());
Writer.AddDeclRef(Context.getInstantiatedFromUsingDecl(D), Record);
Code = serialization::DECL_USING;
@@ -685,7 +682,7 @@
void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) {
VisitNamedDecl(D);
Writer.AddDeclRef(D->getTargetDecl(), Record);
- Writer.AddDeclRef(D->getUsingDecl(), Record);
+ Writer.AddDeclRef(D->UsingOrNextShadow, Record);
Writer.AddDeclRef(Context.getInstantiatedFromUsingShadowDecl(D), Record);
Code = serialization::DECL_USING_SHADOW;
}