diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-13 03:12:56 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-13 03:12:56 +0000 |
commit | 1b7f9cbed1b96b58a6e5f7808ebc9345a76a0936 (patch) | |
tree | 5ee39a7178a4165e20c8fcda710065b645c61cef /lib/Sema/SemaDeclCXX.cpp | |
parent | 4bd265468cb115efd5c87c59d5a5b6af5d24d48c (diff) |
Fix PR10447: lazily building name lookup tables for DeclContexts was broken.
The deferred lookup table building step couldn't accurately tell which Decls
should be included in the lookup table, and consequently built different tables
in some cases.
Fix this by removing lazy building of DeclContext name lookup tables. In
practice, the laziness was frequently not worthwhile in C++, because we
performed lookup into most DeclContexts. In C, it had a bit more value,
since there is no qualified lookup.
In the place of lazy lookup table building, we simply don't build lookup tables
for function DeclContexts at all. Such name lookup tables are not useful, since
they don't capture the scoping information required to correctly perform name
lookup in a function scope.
The resulting performance delta is within the noise on my testing, but appears
to be a very slight win for C++ and a very slight loss for C. The C performance
can probably be recovered (if it is a measurable problem) by avoiding building
the lookup table for the translation unit.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152608 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDeclCXX.cpp')
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index abbbe11561..b6866d04e4 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -5829,14 +5829,15 @@ Decl *Sema::ActOnUsingDirective(Scope *S, } void Sema::PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir) { - // If scope has associated entity, then using directive is at namespace - // or translation unit scope. We add UsingDirectiveDecls, into - // it's lookup structure. - if (DeclContext *Ctx = static_cast<DeclContext*>(S->getEntity())) + // If the scope has an associated entity and the using directive is at + // namespace or translation unit scope, add the UsingDirectiveDecl into + // its lookup structure so qualified name lookup can find it. + DeclContext *Ctx = static_cast<DeclContext*>(S->getEntity()); + if (Ctx && !Ctx->isFunctionOrMethod()) Ctx->addDecl(UDir); else - // Otherwise it is block-sope. using-directives will affect lookup - // only to the end of scope. + // Otherwise, it is at block sope. The using-directives will affect lookup + // only to the end of the scope. S->PushUsingDirective(UDir); } @@ -10195,7 +10196,7 @@ Decl *Sema::ActOnFriendFunctionDecl(Scope *S, Declarator &D, // lookup context is in lexical scope. if (!CurContext->isDependentContext()) { DC = DC->getRedeclContext(); - DC->makeDeclVisibleInContext(ND, /* Recoverable=*/ false); + DC->makeDeclVisibleInContext(ND); if (Scope *EnclosingScope = getScopeForDeclContext(S, DC)) PushOnScopeChains(ND, EnclosingScope, /*AddToContext=*/ false); } |