diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-07-25 23:08:39 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-07-25 23:08:39 +0000 |
commit | 0e5d7b8c6b5559b669ccf7f1dbe2317c42cb766c (patch) | |
tree | 8b88c94b1d2c1fbee01451fc88c1894453b24c22 /clang/lib/Basic/Module.cpp | |
parent | bbf5a3231ce9570a129a125d2705458a16b21adb (diff) | |
download | bcm5719-llvm-0e5d7b8c6b5559b669ccf7f1dbe2317c42cb766c.tar.gz bcm5719-llvm-0e5d7b8c6b5559b669ccf7f1dbe2317c42cb766c.zip |
When we perform dependent name lookup during template instantiation, it's not
sufficient to only consider names visible at the point of instantiation,
because that may not include names that were visible when the template was
defined. More generally, if the instantiation backtrace goes through a module
M, then every declaration visible within M should be available to the
instantiation. Any of those declarations might be part of the interface that M
intended to export to a template that it instantiates.
The fix here has two parts:
1) If we find a non-visible declaration during name lookup during template
instantiation, check whether the declaration was visible from the defining
module of all entities on the active template instantiation stack. The defining
module is not the owning module in all cases: we look at the module in which a
template was defined, not the module in which it was first instantiated.
2) Perform pending instantiations at the end of a module, not at the end of the
translation unit. This is general goodness, since it significantly cuts down
the amount of redundant work that is performed in every TU importing a module,
and also implicitly adds the module containing the point of instantiation to
the set of modules checked for declarations in a lookup within a template
instantiation.
There's a known issue here with template instantiations performed while
building a module, if additional imports are added later on. I'll fix that
in a subsequent commit.
llvm-svn: 187167
Diffstat (limited to 'clang/lib/Basic/Module.cpp')
-rw-r--r-- | clang/lib/Basic/Module.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp index 7b1fe8f37de..7ec5e68fc45 100644 --- a/clang/lib/Basic/Module.cpp +++ b/clang/lib/Basic/Module.cpp @@ -242,6 +242,24 @@ void Module::getExportedModules(SmallVectorImpl<Module *> &Exported) const { } } +void Module::buildVisibleModulesCache() const { + assert(VisibleModulesCache.empty() && "cache does not need building"); + + // This module is visible to itself. + VisibleModulesCache.insert(this); + + llvm::SmallVector<Module*, 4> Exported; + for (unsigned I = 0, N = Imports.size(); I != N; ++I) { + // Every imported module is visible. + VisibleModulesCache.insert(Imports[I]); + + // Every module exported by an imported module is visible. + Imports[I]->getExportedModules(Exported); + VisibleModulesCache.insert(Exported.begin(), Exported.end()); + Exported.clear(); + } +} + void Module::print(raw_ostream &OS, unsigned Indent) const { OS.indent(Indent); if (IsFramework) |