1 // RUN: %clang_cc1 %s -std=c++11 -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
2 // RUN: %clang_cc1 %s -std=c++11 -triple=x86_64-apple-darwin10 -fvisibility=hidden -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-HIDDEN
3 // For clang, "internal" is just an alias for "hidden". We could use it for some
4 // optimization purposes on 32-bit x86, but it's not worth it.
5 // RUN: %clang_cc1 %s -std=c++11 -triple=x86_64-apple-darwin10 -fvisibility=internal -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-HIDDEN
7 #define HIDDEN __attribute__((visibility("hidden")))
8 #define PROTECTED __attribute__((visibility("protected")))
9 #define DEFAULT __attribute__((visibility("default")))
12 // When H is hidden, it should make X hidden, even if the template argument
21 // CHECK: _ZN6test301bE = global
22 // CHECK-HIDDEN: _ZN6test301bE = hidden global
35 X
<int>::definition
<A
> a
;
36 // CHECK: @_ZN6test251aE = global
37 // CHECK-HIDDEN: @_ZN6test251aE = hidden global
44 // CHECK: @_ZN6test285myvecE = global
45 // CHECK-HIDDEN: @_ZN6test285myvecE = hidden global
49 #pragma GCC visibility push(hidden)
53 DEFAULT
extern RECT data_rect
;
54 RECT data_rect
= { -1};
55 #pragma GCC visibility pop
56 // CHECK: @_ZN6test299data_rectE = global
57 // CHECK-HIDDEN: @_ZN6test299data_rectE = global
63 DEFAULT
static int bar
;
67 template struct foo
<int>;
68 // CHECK: _ZN6test403fooIiE3barE = weak_odr global
69 // CHECK-HIDDEN: _ZN6test403fooIiE3barE = weak_odr global
73 // Unlike gcc we propagate the information that foo not only is hidden, but
74 // has been explicitly marked as so. This lets us produce a hidden undefined
81 // CHECK: @_ZN6test413barE = external hidden global
82 // CHECK-HIDDEN: @_ZN6test413barE = external hidden global
86 // Test that we use the visibility of struct foo when instantiating the
87 // template. Note that is a case where we disagree with gcc, it produces
100 // CHECK: _ZN6test481yE = hidden global
101 // CHECK-HIDDEN: _ZN6test481yE = hidden global
107 HIDDEN
static int var1
;
108 template <class U
> HIDDEN
static U var2
;
110 template <class T
> template <class U
>
113 extern template struct DEFAULT foo
<int>;
118 return o
.var1
+ o
.var2
<int> + p
.var1
+ p
.var2
<int>;
120 // CHECK: @_ZN6test723fooIiE4var1E = external hidden global i32
121 // CHECK-NEXT: @_ZN6test723fooIiE4var2IiEE = linkonce_odr global i32 0
122 // CHECK-NEXT: @_ZN6test723fooIlE4var1E = external hidden global i32
123 // CHECK-NEXT: @_ZN6test723fooIlE4var2IiEE = linkonce_odr global i32 0
127 struct HIDDEN foo
{};
128 DEFAULT foo da
, db
, dc
, dd
;
129 HIDDEN foo ha
, hb
, hc
, hd
;
130 template<foo
*z
> DEFAULT
int var
;
132 template int var
<&da
>;
133 template int DEFAULT var
<&db
>;
134 template int HIDDEN var
<&dc
>;
135 template int var
<&ha
>;
136 template int DEFAULT var
<&hb
>;
137 template int HIDDEN var
<&hc
>;
139 int use() { return var
<&dd
> + var
<&hd
>; }
140 // CHECK: @_ZN6test733varIXadL_ZNS_2daEEEEE = weak_odr hidden global i32 0
141 // CHECK-NEXT: @_ZN6test733varIXadL_ZNS_2dbEEEEE = weak_odr global i32 0
142 // CHECK-NEXT: @_ZN6test733varIXadL_ZNS_2dcEEEEE = weak_odr hidden global i32 0
143 // CHECK-NEXT: @_ZN6test733varIXadL_ZNS_2haEEEEE = weak_odr hidden global i32 0
144 // CHECK-NEXT: @_ZN6test733varIXadL_ZNS_2hbEEEEE = weak_odr global i32 0
145 // CHECK-NEXT: @_ZN6test733varIXadL_ZNS_2hcEEEEE = weak_odr hidden global i32 0
146 // CHECK: @_ZN6test733varIXadL_ZNS_2ddEEEEE = linkonce_odr hidden global i32 0
147 // CHECK-NEXT: @_ZN6test733varIXadL_ZNS_2hdEEEEE = linkonce_odr hidden global i32 0
149 // CHECK-HIDDEN: @_ZN6test733varIXadL_ZNS_2daEEEEE = weak_odr hidden global i32 0
150 // CHECK-HIDDEN-NEXT: @_ZN6test733varIXadL_ZNS_2dbEEEEE = weak_odr global i32 0
151 // CHECK-HIDDEN-NEXT: @_ZN6test733varIXadL_ZNS_2dcEEEEE = weak_odr hidden global i32 0
152 // CHECK-HIDDEN-NEXT: @_ZN6test733varIXadL_ZNS_2haEEEEE = weak_odr hidden global i32 0
153 // CHECK-HIDDEN-NEXT: @_ZN6test733varIXadL_ZNS_2hbEEEEE = weak_odr global i32 0
154 // CHECK-HIDDEN-NEXT: @_ZN6test733varIXadL_ZNS_2hcEEEEE = weak_odr hidden global i32 0
155 // CHECK-HIDDEN: @_ZN6test733varIXadL_ZNS_2ddEEEEE = linkonce_odr hidden global i32 0
156 // CHECK-HIDDEN-NEXT: @_ZN6test733varIXadL_ZNS_2hdEEEEE = linkonce_odr hidden global i32 0
159 // CHECK: @_ZN5Test425VariableInHiddenNamespaceE = hidden global i32 10
160 // CHECK: @_ZN5Test71aE = hidden global
161 // CHECK: @_ZN5Test71bE = global
162 // CHECK: @test9_var = global
163 // CHECK-HIDDEN: @test9_var = global
164 // CHECK: @_ZN6Test121A6hiddenE = external hidden global
165 // CHECK: @_ZN6Test121A7visibleE = external global
166 // CHECK-HIDDEN: @_ZN6Test121A6hiddenE = external hidden global
167 // CHECK-HIDDEN: @_ZN6Test121A7visibleE = external global
168 // CHECK: @_ZN6Test131B1aE = hidden global
169 // CHECK: @_ZN6Test131C1aE = global
170 // CHECK-HIDDEN: @_ZN6Test131B1aE = hidden global
171 // CHECK-HIDDEN: @_ZN6Test131C1aE = global
172 // CHECK: @_ZN6Test143varE = external global
173 // CHECK-HIDDEN: @_ZN6Test143varE = external global
174 // CHECK: @_ZN6Test154TempINS_1AEE5Inner6bufferE = external global [0 x i8]
175 // CHECK-HIDDEN: @_ZN6Test154TempINS_1AEE5Inner6bufferE = external global [0 x i8]
176 // CHECK: @_ZTVN6test701BE = external hidden unnamed_addr constant { [5 x ptr] }, align 8
177 // CHECK: @_ZTTN6test701BE = external hidden unnamed_addr constant [2 x ptr], align 8
192 void C
<int>::D::g() {
194 // CHECK: _ZTVN6test271CIiE1DE = unnamed_addr constant
195 // CHECK-HIDDEN: _ZTVN6test271CIiE1DE = unnamed_addr constant
198 // CHECK: @_ZTVN5Test63fooE = linkonce_odr hidden unnamed_addr constant
200 // CHECK-HIDDEN: @_ZTVN6Test161AIcEE = external unnamed_addr constant
201 // CHECK-HIDDEN: @_ZTTN6Test161AIcEE = external unnamed_addr constant
203 // CHECK: @_ZZN6test681fC1EvE4test = linkonce_odr global
204 // CHECK-HIDDEN: @_ZZN6test681fC1EvE4test = linkonce_odr hidden global
206 // CHECK: @_ZGVZN6test681fC1EvE4test = linkonce_odr global
207 // CHECK-HIDDEN: @_ZGVZN6test681fC1EvE4test = linkonce_odr hidden global
209 // CHECK-HIDDEN: @_ZTVN6test701DE = linkonce_odr hidden unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZTIN6test701DE] }, align 8
210 // CHECK-HIDDEN: @_ZTTN6test701DE = linkonce_odr hidden unnamed_addr constant [1 x ptr] [ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTVN6test701DE, i32 0, inrange i32 0, i32 3)], align 8
212 // CHECK: @_ZZN6Test193fooIiEEvvE1a = linkonce_odr global
213 // CHECK-HIDDEN: @_ZZN6Test193fooIiEEvvE1a = linkonce_odr hidden global
215 // CHECK: @_ZGVZN6Test193fooIiEEvvE1a = linkonce_odr global i64
216 // CHECK-HIDDEN: @_ZGVZN6Test193fooIiEEvvE1a = linkonce_odr hidden global i64
219 // CHECK-LABEL: define hidden void @_ZN5Test11fEv
229 // A::f is a member function of a hidden class.
230 // CHECK-LABEL: define hidden void @_ZN5Test21A1fEv
241 // B is a nested class where its parent class is hidden.
242 // CHECK-LABEL: define hidden void @_ZN5Test31A1B1fEv
246 namespace Test4 HIDDEN
{
247 int VariableInHiddenNamespace
= 10;
249 // Test4::g is in a hidden namespace.
250 // CHECK-LABEL: define hidden void @_ZN5Test41gEv
257 // A has default visibility.
258 // CHECK-LABEL: define void @_ZN5Test41A1fEv
264 namespace NS HIDDEN
{
265 // f is in NS which is hidden.
266 // CHECK-LABEL: define hidden void @_ZN5Test52NS1fEv()
271 // g is in NS, but this NS decl is not hidden.
272 // CHECK-LABEL: define void @_ZN5Test52NS1gEv
281 virtual void bar() = 0;
283 virtual void zonk() {}
286 struct barc
: public foo
{
298 template <A
&> struct Aref
{
302 class B
: public A
{};
305 // CHECK-LABEL: define linkonce_odr hidden void @_ZN5Test74ArefIL_ZNS_1aEEE3fooEv()
314 // CHECK-HIDDEN-LABEL: define hidden void @_ZN5Test83barEv()
315 // CHECK-HIDDEN: declare void @_ZN5Test83fooEv()
326 struct A
{ int field
; };
327 void DEFAULT
test9_fun(struct A
*a
) { }
328 struct A DEFAULT test9_var
; // above
330 // CHECK-LABEL: define void @test9_fun(
331 // CHECK-HIDDEN-LABEL: define void @test9_fun(
347 // CHECK-LABEL: define void @_ZN6Test101B3fooEPNS_1AE(
348 // CHECK-HIDDEN-LABEL: define void @_ZN6Test101B3fooEPNS_1AE(
356 void DEFAULT
bar() {}
365 // CHECK-LABEL: define linkonce_odr void @_ZN6Test111A3fooEv(
366 // CHECK-LABEL: define linkonce_odr void @_ZN6Test111A3barEv(
367 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6Test111A3fooEv(
368 // CHECK-HIDDEN-LABEL: define linkonce_odr void @_ZN6Test111A3barEv(
371 // Tested at top of file.
374 // This is hidden in all cases: the explicit attribute takes
375 // priority over -fvisibility on the parent.
376 static int hidden HIDDEN
;
378 // This is default in all cases because it's only a declaration.
388 // Tested at top of file.
392 // Should be hidden in all cases.
398 // Should be default in all cases.
405 // Tested at top of file.
407 // Neither the visibility of the type nor -fvisibility=hidden should
408 // apply to declarations.
409 extern struct A
*var
;
411 struct A
*test() { return var
; }
416 template <class T
> struct Temp
{
418 static char buffer
[0];
423 return Temp
<A
>::Inner::buffer
;
428 struct Base1
{ virtual void foo(); };
429 struct Base2
: virtual Base1
{ virtual void foo(); };
430 template <class T
> struct A
: virtual Base1
, Base2
{
433 extern template struct A
<char>;
444 static void DEFAULT
bar();
445 static void HIDDEN
baz();
449 static void DEFAULT
bar();
450 static void HIDDEN
baz();
462 // CHECK: declare hidden void @_ZN6Test171A3fooEv()
463 // CHECK: declare void @_ZN6Test171A3barEv()
464 // CHECK: declare hidden void @_ZN6Test171A3bazEv()
465 // CHECK: declare void @_ZN6Test171A1B3fooEv()
466 // CHECK: declare void @_ZN6Test171A1B3barEv()
467 // CHECK: declare hidden void @_ZN6Test171A1B3bazEv()
468 // CHECK-HIDDEN: declare hidden void @_ZN6Test171A3fooEv()
469 // CHECK-HIDDEN: declare void @_ZN6Test171A3barEv()
470 // CHECK-HIDDEN: declare hidden void @_ZN6Test171A3bazEv()
471 // CHECK-HIDDEN: declare void @_ZN6Test171A1B3fooEv()
472 // CHECK-HIDDEN: declare void @_ZN6Test171A1B3barEv()
473 // CHECK-HIDDEN: declare hidden void @_ZN6Test171A1B3bazEv()
477 template <class T
> struct HIDDEN A
{
479 static void DEFAULT
bar();
480 static void HIDDEN
baz();
484 static void DEFAULT
bar();
485 static void HIDDEN
baz();
504 // CHECK: declare hidden void @_ZN6Test181AIiE3fooEv()
505 // CHECK: declare void @_ZN6Test181AIiE3barEv()
506 // CHECK: declare hidden void @_ZN6Test181AIiE3bazEv()
507 // CHECK: declare void @_ZN6Test181AIiE1B3fooEv()
508 // CHECK: declare void @_ZN6Test181AIiE1B3barEv()
509 // CHECK: declare hidden void @_ZN6Test181AIiE1B3bazEv()
510 // CHECK: declare hidden void @_ZN6Test181AINS_1HEE3fooEv()
511 // CHECK: declare hidden void @_ZN6Test181AINS_1HEE3barEv()
512 // CHECK: declare hidden void @_ZN6Test181AINS_1HEE3bazEv()
513 // CHECK: declare hidden void @_ZN6Test181AINS_1HEE1B3fooEv()
514 // CHECK: declare hidden void @_ZN6Test181AINS_1HEE1B3barEv()
515 // CHECK: declare hidden void @_ZN6Test181AINS_1HEE1B3bazEv()
516 // CHECK-HIDDEN: declare hidden void @_ZN6Test181AIiE3fooEv()
517 // CHECK-HIDDEN: declare void @_ZN6Test181AIiE3barEv()
518 // CHECK-HIDDEN: declare hidden void @_ZN6Test181AIiE3bazEv()
519 // CHECK-HIDDEN: declare void @_ZN6Test181AIiE1B3fooEv()
520 // CHECK-HIDDEN: declare void @_ZN6Test181AIiE1B3barEv()
521 // CHECK-HIDDEN: declare hidden void @_ZN6Test181AIiE1B3bazEv()
522 // CHECK-HIDDEN: declare hidden void @_ZN6Test181AINS_1HEE3fooEv()
523 // CHECK-HIDDEN: declare hidden void @_ZN6Test181AINS_1HEE3barEv()
524 // CHECK-HIDDEN: declare hidden void @_ZN6Test181AINS_1HEE3bazEv()
525 // CHECK-HIDDEN: declare hidden void @_ZN6Test181AINS_1HEE1B3fooEv()
526 // CHECK-HIDDEN: declare hidden void @_ZN6Test181AINS_1HEE1B3barEv()
527 // CHECK-HIDDEN: declare hidden void @_ZN6Test181AINS_1HEE1B3bazEv()
531 struct A
{ A(); ~A(); };
533 // Tested at top of file.
534 template <class T
> void foo() {
543 // Various things with class template specializations.
545 template <unsigned> struct HIDDEN A
{};
547 // An explicit specialization inherits the explicit visibility of
549 template <> struct A
<0> {
554 // CHECK-LABEL: define hidden void @_ZN6Test201AILj0EE5test0Ev()
555 void A
<0>::test0() {}
557 // CHECK: declare hidden void @_ZN6Test201AILj0EE5test1Ev()
562 // ...unless that's explicitly overridden.
563 template <> struct DEFAULT A
<1> {
568 // CHECK-LABEL: define void @_ZN6Test201AILj1EE5test2Ev()
569 void A
<1>::test2() {}
571 // CHECK: declare void @_ZN6Test201AILj1EE5test3Ev()
576 // But we should assume that an unknown specialization has the
577 // explicit visibility settings of the template.
578 template <class T
> struct B
{
579 static void test4() {}
583 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6Test201BINS_1AILj2EEEE5test4Ev()
588 // CHECK: declare hidden void @_ZN6Test201BINS_1AILj2EEEE5test5Ev()
597 template<En
> struct A
{
598 DEFAULT
void foo() {}
601 // CHECK-LABEL: define weak_odr void @_ZN6test211AILNS_2EnE0EE3fooEv(
602 template void A
<en
>::foo();
605 // Visibility on explicit specializations should take precedence.
610 template <class T
> struct B
{};
611 template <> struct DEFAULT B
<A1
> {
615 template <> struct B
<A2
> {
626 // CHECK: declare void @_ZN6test221BINS_2A1EE3fooEv()
627 // CHECK-LABEL: define linkonce_odr void @_ZN6test221BINS_2A1EE3barEv()
628 // CHECK: declare void @_ZN6test221BINS_2A2EE3fooEv()
629 // CHECK-LABEL: define linkonce_odr void @_ZN6test221BINS_2A2EE3barEv()
630 // CHECK-HIDDEN: declare void @_ZN6test221BINS_2A1EE3fooEv()
631 // CHECK-HIDDEN-LABEL: define linkonce_odr void @_ZN6test221BINS_2A1EE3barEv()
632 // CHECK-HIDDEN: declare void @_ZN6test221BINS_2A2EE3fooEv()
633 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test221BINS_2A2EE3barEv()
637 namespace foo DEFAULT
{
643 template class foo::bar
<char>;
644 // CHECK-LABEL: define weak_odr void @_ZN7PR101133foo3barIcE3zedEv
645 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN7PR101133foo3barIcE3zedEv
649 template class foo::bar
<zed
>;
650 // CHECK-LABEL: define weak_odr void @_ZN7PR101133foo3barINS_3zedEE3zedEv
651 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN7PR101133foo3barINS_3zedEE3zedEv
655 template<class T
> struct Class
{
659 template class DEFAULT Class
<char>;
660 // CHECK-LABEL: define weak_odr void @_ZNK7PR116905ClassIcE4sizeEv
661 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZNK7PR116905ClassIcE4sizeEv
663 template<class T
> void Method() {}
664 template DEFAULT
void Method
<char>();
665 // CHECK-LABEL: define weak_odr void @_ZN7PR116906MethodIcEEvv
666 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN7PR116906MethodIcEEvv
669 namespace PR11690_2
{
670 namespace foo DEFAULT
{
672 template<typename T1
, typename T2
= bar
>
680 template class foo::zed
<baz
>;
681 // CHECK-LABEL: define weak_odr void @_ZN9PR11690_23foo3zedINS_3bazENS0_3barEE3barEv
682 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN9PR11690_23foo3zedINS_3bazENS0_3barEE3barEv
686 // Having a template argument that is explicitly visible should not make
687 // the template instantiation visible.
688 template <typename T
>
700 // CHECK-LABEL: define linkonce_odr void @_ZN6test231XINS_1AEE1fEv
701 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test231XINS_1AEE1fEv
705 template <typename P1
>
706 void Bind(const P1
& p1
) {
709 class DEFAULT Version
{ };
714 // CHECK-LABEL: define linkonce_odr void @_ZN7PR120014BindINS_7VersionEEEvRKT_
715 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN7PR120014BindINS_7VersionEEEvRKT_
722 template <typename T
>
730 // CHECK-LABEL: define linkonce_odr void @_ZN6test241S3memINS_1AEEEvv
731 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test241S3memINS_1AEEEvv
743 // CHECK-LABEL: define void @_ZN6test261CIiE1fEv
744 // CHECK-HIDDEN-LABEL: define void @_ZN6test261CIiE1fEv
750 static void DEFAULT
baz();
756 // CHECK: declare void @_ZN6test311A1B3bazEv()
757 // CHECK-HIDDEN: declare void @_ZN6test311A1B3bazEv()
768 // CHECK-LABEL: define void @_ZN6test321A1B3bazEv
769 // CHECK-HIDDEN-LABEL: define void @_ZN6test321A1B3bazEv
779 template class DEFAULT foo
<zed
>;
780 // CHECK-LABEL: define weak_odr void @_ZN6test333fooINS_3zedEE3barEv
781 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test333fooINS_3zedEE3barEv
789 template DEFAULT
void bar
<foo
>();
790 // CHECK-LABEL: define weak_odr void @_ZN6test343barINS_3fooEEEvv
791 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test343barINS_3fooEEEvv
795 // This is a really ugly testcase. GCC propagates the DEFAULT in zed's
796 // definition. It's not really clear what we can do here, because we
797 // produce the symbols before even seeing the DEFAULT definition of zed.
798 // FIXME: Maybe the best thing to do here is error? It's certainly hard
799 // to argue that this ought to be valid.
805 template class foo
<zed
>;
808 // CHECK-LABEL: define weak_odr void @_ZN6test353fooINS_3zedEE3barEv
809 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test353fooINS_3zedEE3barEv
813 template<typename T1
, typename T2
>
819 template class foo
<S1
, S2
>;
820 // CHECK-LABEL: define weak_odr hidden void @_ZN6test363fooINS_2S1ENS_2S2EE3barEv
821 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test363fooINS_2S1ENS_2S2EE3barEv
828 DEFAULT
void bar() {}
829 template DEFAULT
void bar
<foo
>();
830 // CHECK-LABEL: define weak_odr void @_ZN6test373barINS_3fooEEEvv
831 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test373barINS_3fooEEEvv
841 template class foo
<zed
>;
842 // CHECK-LABEL: define weak_odr hidden void @_ZN6test383fooINS_3zedEE3barEv
843 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test383fooINS_3zedEE3barEv
847 class DEFAULT default_t
;
848 class HIDDEN hidden_t
;
849 template <class T
> class A
{
850 template <class U
> class B
{
851 HIDDEN
void hidden() {}
853 template <class V
> void temp() {}
856 template class DEFAULT A
<hidden_t
>;
857 template class DEFAULT A
<hidden_t
>::B
<hidden_t
>;
858 template void A
<hidden_t
>::B
<hidden_t
>::temp
<default_t
>();
859 template void A
<hidden_t
>::B
<hidden_t
>::temp
<hidden_t
>();
861 // CHECK-LABEL: define weak_odr hidden void @_ZN6test391AINS_8hidden_tEE1BIS1_E6hiddenEv
862 // CHECK-LABEL: define weak_odr void @_ZN6test391AINS_8hidden_tEE1BIS1_E6noattrEv
863 // CHECK-LABEL: define weak_odr void @_ZN6test391AINS_8hidden_tEE1BIS1_E4tempINS_9default_tEEEvv
865 // GCC produces a default for this one. Why?
866 // CHECK-LABEL: define weak_odr hidden void @_ZN6test391AINS_8hidden_tEE1BIS1_E4tempIS1_EEvv
868 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test391AINS_8hidden_tEE1BIS1_E6hiddenEv
869 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test391AINS_8hidden_tEE1BIS1_E6noattrEv
870 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test391AINS_8hidden_tEE1BIS1_E4tempINS_9default_tEEEvv
872 // GCC produces a default for this one. Why?
873 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test391AINS_8hidden_tEE1BIS1_E4tempIS1_EEvv
883 struct HIDDEN bar
<foo
> {
884 DEFAULT
static void zed();
886 void bar
<foo
>::zed() {
888 // CHECK-LABEL: define void @_ZN6test423barINS_3fooEE3zedEv
889 // CHECK-HIDDEN-LABEL: define void @_ZN6test423barINS_3fooEE3zedEv
899 DEFAULT
void bar
<foo
>() {
901 // CHECK-LABEL: define void @_ZN6test433barINS_3fooEEEvv
902 // CHECK-HIDDEN-LABEL: define void @_ZN6test433barINS_3fooEEEvv
906 template <typename T
>
913 template struct DEFAULT foo
<bar
>;
915 // CHECK-LABEL: define internal void @_ZN6test443fooINS_12_GLOBAL__N_13barEEC1Ev
916 // CHECK-HIDDEN-LABEL: define internal void @_ZN6test443fooINS_12_GLOBAL__N_13barEEC1Ev
920 template <typename T
>
922 template <typename T2
>
930 template struct DEFAULT foo
<int>::bar
<zed
>;
931 foo
<int>::bar
<zed
> x
;
932 // CHECK-LABEL: define internal void @_ZN6test453fooIiE3barINS_12_GLOBAL__N_13zedEEC1Ev
933 // CHECK-HIDDEN-LABEL: define internal void @_ZN6test453fooIiE3barINS_12_GLOBAL__N_13zedEEC1Ev
937 template <typename T
>
943 template DEFAULT
void foo
<bar
>();
947 // CHECK-LABEL: define internal void @_ZN6test463fooINS_12_GLOBAL__N_13barEEEvv
948 // CHECK-HIDDEN-LABEL: define internal void @_ZN6test463fooINS_12_GLOBAL__N_13barEEEvv
953 template <typename T
>
960 template DEFAULT
void foo::bar
<zed
>();
964 // CHECK-LABEL: define internal void @_ZN6test473foo3barINS_12_GLOBAL__N_13zedEEEvv
965 // CHECK-HIDDEN-LABEL: define internal void @_ZN6test473foo3barINS_12_GLOBAL__N_13zedEEEvv
969 // Test that we use the visibility of struct foo when instantiating the
970 // template. Note that is a case where we disagree with gcc, it produces
984 template void bar::zed
<&x
>();
985 // CHECK-LABEL: define weak_odr hidden void @_ZN6test493bar3zedIXadL_ZNS_1xEEEEEvv
986 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test493bar3zedIXadL_ZNS_1xEEEEEvv
990 // Test that we use the visibility of struct foo when instantiating the
991 // template. Note that is a case where we disagree with gcc, it produces
1002 template void bar
<&x
>::zed();
1003 // CHECK-LABEL: define weak_odr hidden void @_ZN6test503barIXadL_ZNS_1xEEEE3zedEv
1004 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test503barIXadL_ZNS_1xEEEE3zedEv
1008 // Test that we use the visibility of struct foo when instantiating the
1009 // template. Note that is a case where we disagree with gcc, it produces
1010 // a default symbol.
1012 struct HIDDEN foo
{};
1013 DEFAULT foo da
, db
, dc
, dd
, de
, df
;
1014 HIDDEN foo ha
, hb
, hc
, hd
, he
, hf
;
1016 void DEFAULT
zed() {
1018 template void zed
<&da
>();
1019 // CHECK-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2daEEEEEvv(
1020 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2daEEEEEvv(
1022 template void DEFAULT zed
<&db
>();
1023 // CHECK-LABEL: define weak_odr void @_ZN6test513zedIXadL_ZNS_2dbEEEEEvv(
1024 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test513zedIXadL_ZNS_2dbEEEEEvv(
1026 template void HIDDEN zed
<&dc
>();
1027 // CHECK-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2dcEEEEEvv(
1028 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2dcEEEEEvv(
1030 template void zed
<&ha
>();
1031 // CHECK-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2haEEEEEvv(
1032 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2haEEEEEvv(
1034 template void DEFAULT zed
<&hb
>();
1035 // CHECK-LABEL: define weak_odr void @_ZN6test513zedIXadL_ZNS_2hbEEEEEvv(
1036 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test513zedIXadL_ZNS_2hbEEEEEvv(
1038 template void HIDDEN zed
<&hc
>();
1039 // CHECK-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2hcEEEEEvv(
1040 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2hcEEEEEvv(
1042 #pragma GCC visibility push(hidden)
1043 template void zed
<&dd
>();
1044 template void zed
<&hd
>();
1045 template void DEFAULT zed
<&he
>();
1046 #pragma GCC visibility pop
1047 // CHECK-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2ddEEEEEvv(
1048 // CHECK-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2hdEEEEEvv(
1049 // CHECK-LABEL: define weak_odr void @_ZN6test513zedIXadL_ZNS_2heEEEEEvv(
1050 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2ddEEEEEvv(
1051 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2hdEEEEEvv(
1052 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test513zedIXadL_ZNS_2heEEEEEvv(
1058 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test513zedIXadL_ZNS_2dfEEEEEvv(
1059 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test513zedIXadL_ZNS_2hfEEEEEvv(
1060 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test513zedIXadL_ZNS_2dfEEEEEvv(
1061 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test513zedIXadL_ZNS_2hfEEEEEvv(
1065 // Test that we use the linkage of struct foo when instantiating the
1066 // template. Note that is a case where we disagree with gcc, it produces
1067 // an external symbol.
1079 // CHECK-LABEL: define internal void @_ZN6test523zedILPNS_12_GLOBAL__N_13fooE0EEEvv
1080 // CHECK-HIDDEN-LABEL: define internal void @_ZN6test523zedILPNS_12_GLOBAL__N_13fooE0EEEvv
1084 template<typename _Tp
> struct vector
{
1085 static void _M_fill_insert();
1087 #pragma GCC visibility push(hidden)
1088 // GCC doesn't seem to use the visibility of enums at all, we do.
1091 // GCC fails to mark this specialization hidden, we mark it.
1093 struct vector
<int> {
1094 static void _M_fill_insert();
1097 vector
<unsigned>::_M_fill_insert();
1098 vector
<int>::_M_fill_insert();
1099 vector
<zed
>::_M_fill_insert();
1101 #pragma GCC visibility pop
1102 // CHECK: declare void @_ZN6test536vectorIjE14_M_fill_insertEv
1103 // CHECK-HIDDEN: declare void @_ZN6test536vectorIjE14_M_fill_insertEv
1104 // CHECK: declare hidden void @_ZN6test536vectorIiE14_M_fill_insertEv
1105 // CHECK-HIDDEN: declare hidden void @_ZN6test536vectorIiE14_M_fill_insertEv
1106 // CHECK: declare hidden void @_ZN6test536vectorINS_3zedEE14_M_fill_insertEv
1107 // CHECK-HIDDEN: declare hidden void @_ZN6test536vectorINS_3zedEE14_M_fill_insertEv
1115 #pragma GCC visibility push(hidden)
1122 #pragma GCC visibility pop
1123 // CHECK: declare hidden void @_ZN6test543fooINS_3zedEE3barEv
1124 // CHECK-HIDDEN: declare hidden void @_ZN6test543fooINS_3zedEE3barEv
1132 template <class T
> struct foo
;
1136 // CHECK: declare hidden void @_ZN6test553fooIiE3barEv
1137 // CHECK-HIDDEN: declare hidden void @_ZN6test553fooIiE3barEv
1141 template <class T
> struct foo
;
1149 // CHECK: declare hidden void @_ZN6test563fooIiE3barEv
1150 // CHECK-HIDDEN: declare hidden void @_ZN6test563fooIiE3barEv
1154 #pragma GCC visibility push(hidden)
1157 void bar(foo
<int>*);
1165 #pragma GCC visibility pop
1166 // CHECK: declare hidden void @_ZN6test573fooIiE3zedEv
1167 // CHECK-HIDDEN: declare hidden void @_ZN6test573fooIiE3zedEv
1171 #pragma GCC visibility push(hidden)
1173 template<typename T
>
1174 struct DEFAULT bar
{
1181 #pragma GCC visibility pop
1182 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test583barINS_3fooEE3zedEv
1183 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test583barINS_3fooEE3zedEv
1189 typedef int (*foo
)();
1190 template<foo x
, foo y
>
1194 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test594testIXadL_ZNS_1gEvEEXadL_ZNS_1fEvEEEEvv
1195 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test594testIXadL_ZNS_1gEvEEXadL_ZNS_1fEvEEEEvv
1198 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test594testIXadL_ZNS_1fEvEEXadL_ZNS_1gEvEEEEvv
1199 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test594testIXadL_ZNS_1fEvEEXadL_ZNS_1gEvEEEEvv
1208 template<template<int> class x
, template<int> class y
>
1212 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test604testINS_1aENS_1bEEEvv
1213 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test604testINS_1aENS_1bEEEvv
1216 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test604testINS_1bENS_1aEEEvv
1217 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test604testINS_1bENS_1aEEEvv
1222 template <typename T1
>
1229 inline void Class1
<int>::f2()
1232 void g(Class1
<int> *x
) {
1237 // Just test that we don't crash. Currently we apply this attribute. Current
1238 // gcc issues a warning about it being unused since "the type is already
1239 // defined". We should probably do the same.
1240 template class HIDDEN Class1
<int>;
1244 template <typename T1
>
1251 inline void Class1
<int>::f2()
1254 void g(Class1
<int> *x
) {
1259 template class HIDDEN Class1
<int>;
1260 // Just test that we don't crash. Currently we apply this attribute. Current
1261 // gcc issues a warning about it being unused since "the type is already
1262 // defined". We should probably do the same.
1266 enum HIDDEN E
{ E0
};
1268 template <E
> static void foo() {}
1270 template <E
> struct B
{
1271 static void foo() {}
1279 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test631A3fooILNS_1EE0EEEvv()
1280 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test631A1BILNS_1EE0EE3fooEv()
1283 // Don't ignore the visibility of template arguments just because we
1284 // explicitly instantiated something.
1287 template <class P
> struct B
{
1288 static DEFAULT
void foo() {}
1291 template class B
<A
>;
1292 // CHECK-LABEL: define weak_odr hidden void @_ZN6test641BINS_1AEE3fooEv()
1297 template <class T
> struct B
{
1299 template <class U
> static void funcT1();
1300 template <class U
> static void funcT2();
1302 template <class U
> class InnerT
{};
1304 template <template <class T
> class Temp
> struct C
{
1305 static void foo() {}
1308 // CHECK-LABEL: define void @_ZN6test651BINS_1AEE4funcEv()
1309 template <> DEFAULT
void B
<A
>::func() {}
1311 // CHECK-LABEL: define void @_ZN6test651BINS_1AEE6funcT2IS1_EEvv()
1312 template <> template <> DEFAULT
void B
<A
>::funcT2
<A
>() {}
1314 // CHECK-LABEL: define linkonce_odr void @_ZN6test651BINS_1AEE6funcT1IiEEvv()
1315 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test651BINS_1AEE6funcT1IS1_EEvv()
1316 template <> template <class T
> DEFAULT
void B
<A
>::funcT1() {}
1318 // CHECK-LABEL: define linkonce_odr void @_ZN6test651BINS_1AEE5Inner3fooEv()
1319 template <> struct DEFAULT B
<A
>::Inner
{
1320 static void foo() {}
1323 // CHECK-LABEL: define linkonce_odr void @_ZN6test651BINS_1AEE6InnerTIiE3fooEv()
1324 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test651BINS_1AEE6InnerTIS1_E3fooEv()
1325 template <> template <class U
> struct DEFAULT B
<A
>::InnerT
{
1326 static void foo() {}
1330 B
<A
>::funcT1
<int>();
1333 B
<A
>::InnerT
<int>::foo();
1334 B
<A
>::InnerT
<A
>::foo();
1337 template class C
<B
<A
>::InnerT
>;
1341 template <typename T
>
1342 struct DEFAULT barT
{
1343 static void zed() {}
1347 template struct barT
<foo
>;
1348 // CHECK-LABEL: define weak_odr void @_ZN6test664barTINS_3fooEE3zedEv
1349 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test664barTINS_3fooEE3zedEv
1352 struct DEFAULT barI
{
1353 static void zed() {}
1356 extern int I DEFAULT
;
1357 template struct barI
<&I
>;
1358 // CHECK-LABEL: define weak_odr void @_ZN6test664barIIXadL_ZNS_1IEEEE3zedEv
1359 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test664barIIXadL_ZNS_1IEEEE3zedEv
1361 typedef void (*fType
)(void);
1363 struct DEFAULT barF
{
1364 static void zed() {}
1368 template struct barF
<F
>;
1369 // CHECK-LABEL: define weak_odr void @_ZN6test664barFIXadL_ZNS_1FEvEEE3zedEv
1370 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test664barFIXadL_ZNS_1FEvEEE3zedEv
1374 template <typename T
>
1375 struct DEFAULT bar
{
1376 static void zed() {}
1381 void f(foo
*rootfoo
);
1385 template struct bar
<foo
>;
1386 // CHECK-LABEL: define weak_odr void @_ZN6test673barINS_3fooEE3zedEv
1387 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test673barINS_3fooEE3zedEv
1391 class A
{ public: ~A(); };
1401 // Check lines at top of file.
1412 namespace foo
__attribute__((visibility("hidden"))) {
1414 // CHECK-LABEL: define void @_ZN6test693foo1fEv
1415 // CHECK-HIDDEN-LABEL: define hidden void @_ZN6test693foo1fEv
1419 // Make sure both the vtable and VTT declarations are marked "hidden"
1423 class HIDDEN B
: virtual A
{
1429 // Make sure both the vtable and VTT declarations are marked "hidden"
1430 // when "-fvisibilty=hidden" is in use.
1432 class D
: virtual C
{};
1434 // Check lines at top of file.
1437 // https://github.com/llvm/llvm-project/issues/31462
1441 static HIDDEN T
zed();
1442 template <class U
> HIDDEN U
bar();
1445 T foo
<T
>::zed() { return {}; }
1446 template <class T
> template <class U
>
1447 U foo
<T
>::bar() { return {}; }
1449 extern template struct DEFAULT foo
<int>;
1454 return o
.zed() + o
.bar
<int>() + p
.zed() + p
.bar
<int>();
1456 /// FIXME: foo<int>::bar is hidden in GCC w/ or w/o -fvisibility=hidden.
1457 // CHECK-LABEL: declare hidden noundef i32 @_ZN6test713fooIiE3zedEv(
1458 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZN6test713fooIiE3barIiEET_v(
1459 // CHECK-LABEL: define linkonce_odr hidden noundef i64 @_ZN6test713fooIlE3zedEv(
1460 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZN6test713fooIlE3barIiEET_v(
1461 // CHECK-HIDDEN-LABEL: declare hidden noundef i32 @_ZN6test713fooIiE3zedEv(
1462 // CHECK-HIDDEN-LABEL: define linkonce_odr noundef i32 @_ZN6test713fooIiE3barIiEET_v(
1463 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden noundef i64 @_ZN6test713fooIlE3zedEv(
1464 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden noundef i32 @_ZN6test713fooIlE3barIiEET_v(