[llvm-bugs] [Bug 36621] New: Lost visibility attr on template friend class
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Mar 6 14:31:00 PST 2018
https://bugs.llvm.org/show_bug.cgi?id=36621
Bug ID: 36621
Summary: Lost visibility attr on template friend class
Product: clang
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: stephan.bergmann.secondary at googlemail.com
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
At least with recent trunk,
> $ cat test.cc
> namespace std { class type_info {}; }
> namespace N {
> template<typename> struct S1 {
> template<typename>
> friend struct __attribute__ ((__type_visibility__("default"))) S2;
> };
> template<typename>
> struct __attribute__ ((__type_visibility__("default"))) S2 {
> S1<void> f();
> };
> }
> void f(N::S2<bool> s) {
> s.f(); // #1
> typeid(N::S2<void>);
> }
>
> $ clang++ -Wno-everything -fvisibility=hidden -c test.cc -S -emit-llvm -o - | grep @_ZTIN1N2S2IvEE
> @_ZTIN1N2S2IvEE = linkonce_odr hidden constant { i8*, i8* } { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv117__class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @_ZTSN1N2S2IvEE, i32 0, i32 0) }
the type info for N::S2<void> is emitted with hidden visibility, although S2
has default visibility. If you comment out the line marked #1, it is correctly
emitted with default visibility (the token "hidden" disappears from the grepped
line).
What happens during the call to LinkageComputer::getDeclLinkageAndVisibility
(lib/AST/Decl.cpp) for N::S2<void> is that getExplicitVisibilityAux is called
on that ClassTemplateSpecializationDecl, so calls
> return getVisibilityOf(spec->getSpecializedTemplate()->getTemplatedDecl(),
> kind);
but that ->getTemplateDecl() points at a CXXRecordDecl that lacks the
TypeVisibilityAttr.
When you look at the -Xclang -ast-dump,
...
> `-ClassTemplateSpecializationDecl 0x7fa7ef867358 <line:3:3, line:6:3> line:3:29 struct S1 definition
> |-DefinitionData pass_in_registers empty aggregate standard_layout trivially_copyable pod trivial literal has_constexpr_non_copy_move_ctor can_const_default_init
> | |-DefaultConstructor exists trivial constexpr needs_implicit defaulted_is_constexpr
> | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
> | |-MoveConstructor exists simple trivial needs_implicit
> | |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param
> | |-MoveAssignment exists simple trivial needs_implicit
> | `-Destructor simple irrelevant trivial
> |-TemplateArgument type 'void'
> |-CXXRecordDecl 0x7fa7ef867d78 prev 0x7fa7ef867358 <col:22, col:29> col:29 implicit struct S1
> |-FriendDecl 0x7fa7ef867f98 <line:4:5, line:5:68> col:68
> | `-ClassTemplateDecl 0x7fa7ef867f28 parent 0x7fa7ef8348f0 prev 0x7fa7ef8353e8 <line:4:5, line:5:68> col:68 S2
> | |-TemplateTypeParmDecl 0x7fa7ef867e10 <line:4:14> col:14 typename depth 0 index 0
> | |-CXXRecordDecl 0x7fa7ef867e90 parent 0x7fa7ef8348f0 prev 0x7fa7ef835350 <line:5:12, col:68> col:68 struct S2
> | |-ClassTemplateSpecialization 0x7fa7ef8676b0 'S2'
> | `-ClassTemplateSpecialization 0x7fa7ef86aa00 'S2'
> `-CXXDestructorDecl 0x7fa7ef868018 <line:3:29> col:29 implicit referenced ~S1 'void () noexcept' inline default trivial
...
there is a specialization of N::S1<void> with a FriendDecl/CXXRecordDecl for S2
lacking the TypeVisibilityAttr, and I think that's the instance that the above
->getTemplateDecl() points at. What I don't know is whether the bug is that
that FriendDecl/CXXRecordDecl for S2 lacks the TypeVisibilityAttr, or that the
above ->getTemplateDecl() points at that specific FriendDecl/CXXRecordDecl
(there are further CXXRecordDecls for S2 in the AST dump, with a proper
TypeVisibilityAttr).
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180306/05d51809/attachment.html>
More information about the llvm-bugs
mailing list