@@ -3663,17 +3663,22 @@ class ASTDeclContextNameLookupTrait {
3663
3663
} // end anonymous namespace
3664
3664
3665
3665
template <typename Visitor>
3666
- static void visitLocalLookupResults (const DeclContext *ConstDC,
3667
- bool NeedToReconcileExternalVisibleStorage,
3668
- Visitor AddLookupResult) {
3666
+ void ASTWriter::visitLocalLookupResults (const DeclContext *ConstDC,
3667
+ Visitor AddLookupResult) {
3669
3668
// FIXME: We need to build the lookups table, which is logically const.
3670
3669
DeclContext *DC = const_cast <DeclContext*>(ConstDC);
3671
3670
assert (DC == DC->getPrimaryContext () && " only primary DC has lookup table" );
3672
3671
3673
3672
SmallVector<DeclarationName, 16 > ExternalNames;
3674
3673
for (auto &Lookup : *DC->buildLookup ()) {
3674
+ // If there are no local declarations in our lookup result, we don't
3675
+ // need to write an entry for the name at all unless we're rewriting
3676
+ // the decl context.
3677
+ if (!Lookup.second .hasLocalDecls () && !isRewritten (cast<Decl>(DC)))
3678
+ continue ;
3679
+
3675
3680
if (Lookup.second .hasExternalDecls () ||
3676
- NeedToReconcileExternalVisibleStorage) {
3681
+ DC-> NeedToReconcileExternalVisibleStorage ) {
3677
3682
// We don't know for sure what declarations are found by this name,
3678
3683
// because the external source might have a different set from the set
3679
3684
// that are in the lookup map, and we can't update it now without
@@ -3697,9 +3702,8 @@ static void visitLocalLookupResults(const DeclContext *ConstDC,
3697
3702
void ASTWriter::AddUpdatedDeclContext (const DeclContext *DC) {
3698
3703
if (UpdatedDeclContexts.insert (DC).second && WritingAST) {
3699
3704
// Ensure we emit all the visible declarations.
3700
- visitLocalLookupResults (DC, DC->NeedToReconcileExternalVisibleStorage ,
3701
- [&](DeclarationName Name,
3702
- DeclContext::lookup_result Result) {
3705
+ visitLocalLookupResults (DC, [&](DeclarationName Name,
3706
+ DeclContext::lookup_result Result) {
3703
3707
for (auto *Decl : Result)
3704
3708
GetDeclRef (getDeclForLocalLookup (getLangOpts (), Decl));
3705
3709
});
@@ -3721,9 +3725,8 @@ ASTWriter::GenerateNameLookupTable(const DeclContext *DC,
3721
3725
SmallVector<NamedDecl *, 8 > ConstructorDecls;
3722
3726
SmallVector<NamedDecl *, 4 > ConversionDecls;
3723
3727
3724
- visitLocalLookupResults (DC, DC->NeedToReconcileExternalVisibleStorage ,
3725
- [&](DeclarationName Name,
3726
- DeclContext::lookup_result Result) {
3728
+ visitLocalLookupResults (DC, [&](DeclarationName Name,
3729
+ DeclContext::lookup_result Result) {
3727
3730
if (Result.empty ())
3728
3731
return ;
3729
3732
0 commit comments