r230727 - [modules] Don't write out name lookup table entries merely because the module
Richard Smith
richard-llvm at metafoo.co.uk
Thu Feb 26 19:40:10 PST 2015
Author: rsmith
Date: Thu Feb 26 21:40:09 2015
New Revision: 230727
URL: http://llvm.org/viewvc/llvm-project?rev=230727&view=rev
Log:
[modules] Don't write out name lookup table entries merely because the module
happened to query them; only write them out if something new was added.
Modified:
cfe/trunk/include/clang/AST/DeclContextInternals.h
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/lib/Serialization/ASTWriter.cpp
Modified: cfe/trunk/include/clang/AST/DeclContextInternals.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclContextInternals.h?rev=230727&r1=230726&r2=230727&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclContextInternals.h (original)
+++ cfe/trunk/include/clang/AST/DeclContextInternals.h Thu Feb 26 21:40:09 2015
@@ -78,6 +78,17 @@ public:
return getAsVectorAndHasExternal().getPointer();
}
+ bool hasLocalDecls() const {
+ if (NamedDecl *Singleton = getAsDecl()) {
+ return !Singleton->isFromASTFile();
+ } else if (DeclsTy *Vec = getAsVector()) {
+ for (auto *D : *Vec)
+ if (!D->isFromASTFile())
+ return true;
+ }
+ return false;
+ }
+
bool hasExternalDecls() const {
return getAsVectorAndHasExternal().getInt();
}
Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=230727&r1=230726&r2=230727&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Thu Feb 26 21:40:09 2015
@@ -477,6 +477,9 @@ private:
void WriteTypeAbbrevs();
void WriteType(QualType T);
+ template<typename Visitor>
+ void visitLocalLookupResults(const DeclContext *DC, Visitor AddLookupResult);
+
uint32_t GenerateNameLookupTable(const DeclContext *DC,
llvm::SmallVectorImpl<char> &LookupTable);
uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC);
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=230727&r1=230726&r2=230727&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Thu Feb 26 21:40:09 2015
@@ -3663,17 +3663,22 @@ public:
} // end anonymous namespace
template<typename Visitor>
-static void visitLocalLookupResults(const DeclContext *ConstDC,
- bool NeedToReconcileExternalVisibleStorage,
- Visitor AddLookupResult) {
+void ASTWriter::visitLocalLookupResults(const DeclContext *ConstDC,
+ Visitor AddLookupResult) {
// FIXME: We need to build the lookups table, which is logically const.
DeclContext *DC = const_cast<DeclContext*>(ConstDC);
assert(DC == DC->getPrimaryContext() && "only primary DC has lookup table");
SmallVector<DeclarationName, 16> ExternalNames;
for (auto &Lookup : *DC->buildLookup()) {
+ // If there are no local declarations in our lookup result, we don't
+ // need to write an entry for the name at all unless we're rewriting
+ // the decl context.
+ if (!Lookup.second.hasLocalDecls() && !isRewritten(cast<Decl>(DC)))
+ continue;
+
if (Lookup.second.hasExternalDecls() ||
- NeedToReconcileExternalVisibleStorage) {
+ DC->NeedToReconcileExternalVisibleStorage) {
// We don't know for sure what declarations are found by this name,
// because the external source might have a different set from the set
// that are in the lookup map, and we can't update it now without
@@ -3697,9 +3702,8 @@ static void visitLocalLookupResults(cons
void ASTWriter::AddUpdatedDeclContext(const DeclContext *DC) {
if (UpdatedDeclContexts.insert(DC).second && WritingAST) {
// Ensure we emit all the visible declarations.
- visitLocalLookupResults(DC, DC->NeedToReconcileExternalVisibleStorage,
- [&](DeclarationName Name,
- DeclContext::lookup_result Result) {
+ visitLocalLookupResults(DC, [&](DeclarationName Name,
+ DeclContext::lookup_result Result) {
for (auto *Decl : Result)
GetDeclRef(getDeclForLocalLookup(getLangOpts(), Decl));
});
@@ -3721,9 +3725,8 @@ ASTWriter::GenerateNameLookupTable(const
SmallVector<NamedDecl *, 8> ConstructorDecls;
SmallVector<NamedDecl *, 4> ConversionDecls;
- visitLocalLookupResults(DC, DC->NeedToReconcileExternalVisibleStorage,
- [&](DeclarationName Name,
- DeclContext::lookup_result Result) {
+ visitLocalLookupResults(DC, [&](DeclarationName Name,
+ DeclContext::lookup_result Result) {
if (Result.empty())
return;
More information about the cfe-commits
mailing list