Commit Graph

29 Commits

Author SHA1 Message Date
Richard Smith a2e7966958 Consistently create a new declaration when merging a pre-existing but
hidden definition with a would-be-parsed redefinition.

This permits a bunch of cleanups. In particular, we no longer need to
take merged definitions into account when checking declaration
visibility, only when checking definition visibility, which makes
certain visibility checks take linear instead of quadratic time.

We could also now remove the UPD_DECL_EXPORTED update record and track
on each declaration whether it was demoted from a definition (as we
already do for variables), but I'm not doing that in this patch to keep
the changes here simpler.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342018 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-12 02:13:47 +00:00
Richard Smith ab693fec04 Push alias-declarations and alias-template declarations into scope even if
they're redeclarations. This is necessary in order for name lookup to correctly
find the most recent declaration of the name (which affects default template
argument lookup and cross-module merging, among other things).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275612 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-15 20:53:25 +00:00
Richard Smith e8bff7792a [modules] Don't try to use the definition of a class if
RequireCompleteType(..., 0) says we're not permitted to do so. The definition
might not be visible, even though we know what it is.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256045 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-18 22:19:11 +00:00
Richard Smith d10ae9b34e [modules] Follow the C++ standard's rule for linkage of enumerators: they have
the linkage of the enumeration. For enumerators of unnamed enumerations, extend
the -Wmodules-ambiguous-internal-linkage extension to allow selecting an
arbitrary enumerator (but only if they all have the same value, otherwise it's
ambiguous).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253010 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-13 03:52:13 +00:00
Richard Smith f1b82542b7 [modules] Simplify and generalize the existing rule for finding hidden
declarations in redeclaration lookup. A declaration is now visible to
lookup if:

 * It is visible (not in a module, or in an imported module), or
 * We're doing redeclaration lookup and it's externally-visible, or
 * We're doing typo correction and looking for unimported decls.

We now support multiple modules having different internal-linkage or no-linkage
definitions of the same name for all entities, not just for functions,
variables, and some typedefs. As previously, if multiple such entities are
visible, any attempt to use them will result in an ambiguity error.

This patch fixes the linkage calculation for a number of entities where we
previously didn't need to get it right (using-declarations, namespace aliases,
and so on).  It also classifies enumerators as always having no linkage, which
is a slight deviation from the C++ standard's definition, but not an observable
change outside modules (this change is being discussed on the -core reflector
currently).

This also removes the prior special case for tag lookup, which made some cases
of this work, but also led to bizarre, bogus "must use 'struct' to refer to type
'Foo' in this scope" diagnostics in C++.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@252960 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-12 22:19:45 +00:00
Richard Smith 42dd19ccb2 Revert r240335.
This failed to solve the problem it was aimed at, and introduced just as many
issues as it resolved. Realistically, we need to deal with the possibility that
multiple modules might define different internal linkage symbols with the same
name, and this isn't a problem unless two such symbols are simultaneously
visible.

The case where two modules define equivalent internal linkage symbols is
handled by r252063: if lookup finds multiple sufficiently-similar entities from
different modules, we just pick one of them as an extension (but we keep them
separate).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@252957 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-12 21:55:58 +00:00
Richard Smith 5df6568d40 [modules] When parsing the base specifiers of a parse-merged class, the current
context is the class itself but lookups should be performed starting with the
lookup parent of the class (class and base members don't shadow types from the
surrounding context because they have not been declared yet).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245236 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-17 20:24:17 +00:00
Richard Smith 0128dc8835 [modules] Make IndirectFieldDecl mergeable to avoid lookup ambiguity when the same anonymous union is defined across multiple modules.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@243940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-04 02:05:09 +00:00
Richard Smith abaf7f0301 [modules] Fix merging support for forward-declared enums with fixed underlying types. A visible declaration is enough to make the type complete, but not enough to make the definition visible.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241743 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-08 21:49:31 +00:00
Richard Smith 4107de1e70 [modules] Merging support for specializations of a function template. This very
rarely matters, but can affect whether two dependent types are canonically
equivalent.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241207 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-01 23:19:58 +00:00
Richard Smith 939a9d5b47 [modules] Don't make out-of-line member specializations of an instantiated
class template specialization visible just because the class template
specialization's definition is visible.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241182 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-01 19:32:54 +00:00
Richard Smith 5fa53a9a30 [modules] Add a flag to disable the feature that permits conflicting redefinitions of internal-linkage symbols that are not visible.
Such conflicts are an accident waiting to happen, and this feature conflicts
with the desire to include existing headers into multiple modules and merge the
results. (In an ideal world, it should not be possible to export internal
linkage symbols from a module, but sadly the glibc and libstdc++ headers
provide 'static inline' functions in a few cases.)


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240335 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-22 21:15:01 +00:00
Richard Smith ebc80e4942 [modules] Ensure that if we merge the definitions of two enumerations, that
making either of them visible makes the merged definition visible.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239969 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-17 23:07:50 +00:00
Richard Smith 94ff30c2f8 [modules] Fix typo in default argument merging.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239954 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-17 22:13:23 +00:00
Richard Smith 078478a40a [modules] If we merge a template, also track that its parameters are merged so
that we know when its default arguments should be visible.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239936 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-17 20:39:41 +00:00
Richard Smith a5c46dbe18 [modules] Improve diagnostic for a template-id that's invalid because a default
argument is not visible.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239934 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-17 20:16:32 +00:00
Richard Smith 2aef2bd4b1 [modules] Fix merging of default template arguments onto friend templates.
Previously we'd complain about redefinition of default arguments when we
instantiated a class with a friend template that inherits its default argument,
because we propagate the default template arguemnt onto the friend when we
reload the AST.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239857 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-16 21:57:05 +00:00
Richard Smith 6e03dd94ce [modules] Simplify -cc1 interface for enabling implicit module maps.
We used to have a flag to enable module maps, and two more flags to enable
implicit module maps. This is all redundant; we don't need any flag for
enabling module maps in the abstract, and we don't usually have -fno- flags for
-cc1. We now have just a single flag, -fimplicit-module-maps, that enables
implicitly searching the file system for module map files and loading them.

The driver interface is unchanged for now. We should probably rename
-fmodule-maps to -fimplicit-module-maps at some point.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239789 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-16 00:08:24 +00:00
Richard Smith a6dd8f13d6 [modules] Better support for redefinitions of an entity from the same module.
Support this across module save/reload and extend the 'missing import'
diagnostics with a list of providing modules.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239750 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-15 20:15:48 +00:00
Richard Smith 70119b2993 [modules] Apply name visibility rules to names found by ADL.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239578 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-12 01:32:13 +00:00
Richard Smith 50c8426bfa [modules] Fix crash with multiple levels of default template argument merging.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239575 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-11 23:46:11 +00:00
Richard Smith 4c83c92a53 [modules] Fix a few places where merging wasn't performed if modules was disabled but local module visibilty was enabled.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239504 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-11 03:05:39 +00:00
Richard Smith 049e702bb3 [modules] Add local submodule visibility support for declarations.
With this change, enabling -fmodules-local-submodule-visibility results in name
visibility rules being applied to submodules of the current module in addition
to imported modules (that is, names no longer "leak" between submodules of the
same top-level module). This also makes it much safer to textually include a
non-modular library into a module: each submodule that textually includes that
library will get its own "copy" of that library, and so the library becomes
visible no matter which including submodule you import.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237473 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-15 20:05:43 +00:00
Richard Smith 74e3a016fd [modules] Allow a function template definition if we have a pre-existing but not visible definition of the same template.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233430 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-27 21:57:41 +00:00
Richard Smith e308538c71 [modules] When merging class definitions, make the retained definition visible
if the merged definition is visible, and perform lookups into all merged copies
of the definition (not just for special members) so that we can complete the
redecl chains for members of the class.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233420 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-27 21:16:39 +00:00
Richard Smith d4edf61101 [modules] Allow a function to be redefined if the old definition is not visible.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233407 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-27 20:16:58 +00:00
Richard Smith 0b27aaf8c2 [modules] Handle defining a tag with a typedef name for linkage purposes on top of an existing imported-but-not-visible definition.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233345 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-27 01:37:43 +00:00
Richard Smith 4babb8dca1 [modules] Handle defining a class template on top of an existing imported-but-not-visible definition.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233341 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-27 00:41:57 +00:00
Richard Smith 441319ae34 [modules] If we reach a definition of a class for which we already have a
non-visible definition, skip the new definition and make the old one visible
instead of trying to parse it again and failing horribly. C++'s ODR allows
us to assume that the two definitions are identical.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233250 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-26 04:09:53 +00:00