r253012 - [modules] When a declaration has non-trivial visibility, check whether it's

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 16 19:09:55 PST 2015


On Mon, Nov 16, 2015 at 7:00 PM, Sean Silva <chisophugis at gmail.com> wrote:

> On Sat, Nov 14, 2015 at 2:30 PM, Richard Smith <richard at metafoo.co.uk>
> wrote:
>
>> On Nov 13, 2015 7:23 PM, "Sean Silva" <chisophugis at gmail.com> wrote:
>> >
>> >
>> >
>> > On Thu, Nov 12, 2015 at 9:14 PM, Richard Smith via cfe-commits <
>> cfe-commits at lists.llvm.org> wrote:
>> >>
>> >> Author: rsmith
>> >> Date: Thu Nov 12 23:14:45 2015
>> >> New Revision: 253012
>> >>
>> >> URL: http://llvm.org/viewvc/llvm-project?rev=253012&view=rev
>> >> Log:
>> >> [modules] When a declaration has non-trivial visibility, check whether
>> it's
>> >
>> >
>> > What is "non-trivial visibility"? Is this "visibility" something that
>> exists in the present C++ language? (e.g. `using namespace std` etc.) or is
>> this a different notion?
>>
>> This is the modules notion of visibility (whether the declaration has
>> been imported or not). Here, non-trivial visibility means "not known to be
>> unconditionally visible", and corresponds to the Hidden flag on the Decl
>> being true.
>>
>
> I just looked at the comment on the `Hidden` flag and it doesn't seem to
> mention anything about being "trivial" or "non-trivial". Why say
> "declaration has non-trivial visibility" instead of just "declaration is
> hidden"? Do they mean different things?
>

Yes; the comment on that flag is out of date. Whether a declaration is
visible is a function of several factors and isn't as simple as checking
that flag. When performing template instantiation, names from unimported
modules (and module-private names from imported modules) can be made
visible if they were visible when the template was defined. When local
submodule visibility is enabled, the visibility of a declaration is
computed each time we reference it, because module visibility is not
monotonically increasing.

If the Hidden flag is false, the declararation is unconditionally visible.
If the Hidden flag is true, the declaration might still be visible,
depending on who's asking and from where.


> -- Sean Silva
>
>
>> > -- Sean Silva
>> >
>> >>
>> >> actually hidden before we check its linkage. This avoids computing the
>> linkage
>> >> "too early" for an anonymous struct with a typedef name for linkage.
>> >>
>> >> Modified:
>> >>     cfe/trunk/include/clang/Sema/Lookup.h
>> >>     cfe/trunk/test/Modules/submodule-visibility.cpp
>> >>
>> >> Modified: cfe/trunk/include/clang/Sema/Lookup.h
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Lookup.h?rev=253012&r1=253011&r2=253012&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/include/clang/Sema/Lookup.h (original)
>> >> +++ cfe/trunk/include/clang/Sema/Lookup.h Thu Nov 12 23:14:45 2015
>> >> @@ -303,8 +303,7 @@ public:
>> >>      if (!D->isInIdentifierNamespace(IDNS))
>> >>        return nullptr;
>> >>
>> >> -    if (!D->isHidden() || isHiddenDeclarationVisible(D) ||
>> >> -        isVisibleSlow(getSema(), D))
>> >> +    if (isVisible(getSema(), D) || isHiddenDeclarationVisible(D))
>> >>        return D;
>> >>
>> >>      return getAcceptableDeclSlow(D);
>> >>
>> >> Modified: cfe/trunk/test/Modules/submodule-visibility.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/submodule-visibility.cpp?rev=253012&r1=253011&r2=253012&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/test/Modules/submodule-visibility.cpp (original)
>> >> +++ cfe/trunk/test/Modules/submodule-visibility.cpp Thu Nov 12
>> 23:14:45 2015
>> >> @@ -28,3 +28,10 @@ int k = n + m; // OK, a and b are visibl
>> >>  #ifndef B
>> >>  #error B is not defined
>> >>  #endif
>> >> +
>> >> +// Ensure we don't compute the linkage of this struct before we find
>> it has a
>> >> +// typedef name for linkage purposes.
>> >> +typedef struct {
>> >> +  int p;
>> >> +  void (*f)(int p);
>> >> +} name_for_linkage;
>> >>
>> >>
>> >> _______________________________________________
>> >> cfe-commits mailing list
>> >> cfe-commits at lists.llvm.org
>> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>> >
>> >
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151116/6c99ff35/attachment.html>


More information about the cfe-commits mailing list