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: @_ZZN6Test193fooIiEEvvE1a = linkonce_odr global
210 // CHECK-HIDDEN: @_ZZN6Test193fooIiEEvvE1a = linkonce_odr hidden global
212 // CHECK: @_ZGVZN6Test193fooIiEEvvE1a = linkonce_odr global i64
213 // CHECK-HIDDEN: @_ZGVZN6Test193fooIiEEvvE1a = linkonce_odr hidden global i64
216 // CHECK-LABEL: define hidden void @_ZN5Test11fEv
226 // A::f is a member function of a hidden class.
227 // CHECK-LABEL: define hidden void @_ZN5Test21A1fEv
238 // B is a nested class where its parent class is hidden.
239 // CHECK-LABEL: define hidden void @_ZN5Test31A1B1fEv
243 namespace Test4 HIDDEN
{
244 int VariableInHiddenNamespace
= 10;
246 // Test4::g is in a hidden namespace.
247 // CHECK-LABEL: define hidden void @_ZN5Test41gEv
254 // A has default visibility.
255 // CHECK-LABEL: define void @_ZN5Test41A1fEv
261 namespace NS HIDDEN
{
262 // f is in NS which is hidden.
263 // CHECK-LABEL: define hidden void @_ZN5Test52NS1fEv()
268 // g is in NS, but this NS decl is not hidden.
269 // CHECK-LABEL: define void @_ZN5Test52NS1gEv
278 virtual void bar() = 0;
280 virtual void zonk() {}
283 struct barc
: public foo
{
295 template <A
&> struct Aref
{
299 class B
: public A
{};
302 // CHECK-LABEL: define linkonce_odr hidden void @_ZN5Test74ArefIL_ZNS_1aEEE3fooEv()
311 // CHECK-HIDDEN-LABEL: define hidden void @_ZN5Test83barEv()
312 // CHECK-HIDDEN: declare void @_ZN5Test83fooEv()
323 struct A
{ int field
; };
324 void DEFAULT
test9_fun(struct A
*a
) { }
325 struct A DEFAULT test9_var
; // above
327 // CHECK-LABEL: define void @test9_fun(
328 // CHECK-HIDDEN-LABEL: define void @test9_fun(
344 // CHECK-LABEL: define void @_ZN6Test101B3fooEPNS_1AE(
345 // CHECK-HIDDEN-LABEL: define void @_ZN6Test101B3fooEPNS_1AE(
353 void DEFAULT
bar() {}
362 // CHECK-LABEL: define linkonce_odr void @_ZN6Test111A3fooEv(
363 // CHECK-LABEL: define linkonce_odr void @_ZN6Test111A3barEv(
364 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6Test111A3fooEv(
365 // CHECK-HIDDEN-LABEL: define linkonce_odr void @_ZN6Test111A3barEv(
368 // Tested at top of file.
371 // This is hidden in all cases: the explicit attribute takes
372 // priority over -fvisibility on the parent.
373 static int hidden HIDDEN
;
375 // This is default in all cases because it's only a declaration.
385 // Tested at top of file.
389 // Should be hidden in all cases.
395 // Should be default in all cases.
402 // Tested at top of file.
404 // Neither the visibility of the type nor -fvisibility=hidden should
405 // apply to declarations.
406 extern struct A
*var
;
408 struct A
*test() { return var
; }
413 template <class T
> struct Temp
{
415 static char buffer
[0];
420 return Temp
<A
>::Inner::buffer
;
425 struct Base1
{ virtual void foo(); };
426 struct Base2
: virtual Base1
{ virtual void foo(); };
427 template <class T
> struct A
: virtual Base1
, Base2
{
430 extern template struct A
<char>;
441 static void DEFAULT
bar();
442 static void HIDDEN
baz();
446 static void DEFAULT
bar();
447 static void HIDDEN
baz();
459 // CHECK: declare hidden void @_ZN6Test171A3fooEv()
460 // CHECK: declare void @_ZN6Test171A3barEv()
461 // CHECK: declare hidden void @_ZN6Test171A3bazEv()
462 // CHECK: declare void @_ZN6Test171A1B3fooEv()
463 // CHECK: declare void @_ZN6Test171A1B3barEv()
464 // CHECK: declare hidden void @_ZN6Test171A1B3bazEv()
465 // CHECK-HIDDEN: declare hidden void @_ZN6Test171A3fooEv()
466 // CHECK-HIDDEN: declare void @_ZN6Test171A3barEv()
467 // CHECK-HIDDEN: declare hidden void @_ZN6Test171A3bazEv()
468 // CHECK-HIDDEN: declare void @_ZN6Test171A1B3fooEv()
469 // CHECK-HIDDEN: declare void @_ZN6Test171A1B3barEv()
470 // CHECK-HIDDEN: declare hidden void @_ZN6Test171A1B3bazEv()
474 template <class T
> struct HIDDEN A
{
476 static void DEFAULT
bar();
477 static void HIDDEN
baz();
481 static void DEFAULT
bar();
482 static void HIDDEN
baz();
501 // CHECK: declare hidden void @_ZN6Test181AIiE3fooEv()
502 // CHECK: declare void @_ZN6Test181AIiE3barEv()
503 // CHECK: declare hidden void @_ZN6Test181AIiE3bazEv()
504 // CHECK: declare void @_ZN6Test181AIiE1B3fooEv()
505 // CHECK: declare void @_ZN6Test181AIiE1B3barEv()
506 // CHECK: declare hidden void @_ZN6Test181AIiE1B3bazEv()
507 // CHECK: declare hidden void @_ZN6Test181AINS_1HEE3fooEv()
508 // CHECK: declare hidden void @_ZN6Test181AINS_1HEE3barEv()
509 // CHECK: declare hidden void @_ZN6Test181AINS_1HEE3bazEv()
510 // CHECK: declare hidden void @_ZN6Test181AINS_1HEE1B3fooEv()
511 // CHECK: declare hidden void @_ZN6Test181AINS_1HEE1B3barEv()
512 // CHECK: declare hidden void @_ZN6Test181AINS_1HEE1B3bazEv()
513 // CHECK-HIDDEN: declare hidden void @_ZN6Test181AIiE3fooEv()
514 // CHECK-HIDDEN: declare void @_ZN6Test181AIiE3barEv()
515 // CHECK-HIDDEN: declare hidden void @_ZN6Test181AIiE3bazEv()
516 // CHECK-HIDDEN: declare void @_ZN6Test181AIiE1B3fooEv()
517 // CHECK-HIDDEN: declare void @_ZN6Test181AIiE1B3barEv()
518 // CHECK-HIDDEN: declare hidden void @_ZN6Test181AIiE1B3bazEv()
519 // CHECK-HIDDEN: declare hidden void @_ZN6Test181AINS_1HEE3fooEv()
520 // CHECK-HIDDEN: declare hidden void @_ZN6Test181AINS_1HEE3barEv()
521 // CHECK-HIDDEN: declare hidden void @_ZN6Test181AINS_1HEE3bazEv()
522 // CHECK-HIDDEN: declare hidden void @_ZN6Test181AINS_1HEE1B3fooEv()
523 // CHECK-HIDDEN: declare hidden void @_ZN6Test181AINS_1HEE1B3barEv()
524 // CHECK-HIDDEN: declare hidden void @_ZN6Test181AINS_1HEE1B3bazEv()
528 struct A
{ A(); ~A(); };
530 // Tested at top of file.
531 template <class T
> void foo() {
540 // Various things with class template specializations.
542 template <unsigned> struct HIDDEN A
{};
544 // An explicit specialization inherits the explicit visibility of
546 template <> struct A
<0> {
551 // CHECK-LABEL: define hidden void @_ZN6Test201AILj0EE5test0Ev()
552 void A
<0>::test0() {}
554 // CHECK: declare hidden void @_ZN6Test201AILj0EE5test1Ev()
559 // ...unless that's explicitly overridden.
560 template <> struct DEFAULT A
<1> {
565 // CHECK-LABEL: define void @_ZN6Test201AILj1EE5test2Ev()
566 void A
<1>::test2() {}
568 // CHECK: declare void @_ZN6Test201AILj1EE5test3Ev()
573 // But we should assume that an unknown specialization has the
574 // explicit visibility settings of the template.
575 template <class T
> struct B
{
576 static void test4() {}
580 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6Test201BINS_1AILj2EEEE5test4Ev()
585 // CHECK: declare hidden void @_ZN6Test201BINS_1AILj2EEEE5test5Ev()
594 template<En
> struct A
{
595 DEFAULT
void foo() {}
598 // CHECK-LABEL: define weak_odr void @_ZN6test211AILNS_2EnE0EE3fooEv(
599 template void A
<en
>::foo();
602 // Visibility on explicit specializations should take precedence.
607 template <class T
> struct B
{};
608 template <> struct DEFAULT B
<A1
> {
612 template <> struct B
<A2
> {
623 // CHECK: declare void @_ZN6test221BINS_2A1EE3fooEv()
624 // CHECK-LABEL: define linkonce_odr void @_ZN6test221BINS_2A1EE3barEv()
625 // CHECK: declare void @_ZN6test221BINS_2A2EE3fooEv()
626 // CHECK-LABEL: define linkonce_odr void @_ZN6test221BINS_2A2EE3barEv()
627 // CHECK-HIDDEN: declare void @_ZN6test221BINS_2A1EE3fooEv()
628 // CHECK-HIDDEN-LABEL: define linkonce_odr void @_ZN6test221BINS_2A1EE3barEv()
629 // CHECK-HIDDEN: declare void @_ZN6test221BINS_2A2EE3fooEv()
630 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test221BINS_2A2EE3barEv()
634 namespace foo DEFAULT
{
640 template class foo::bar
<char>;
641 // CHECK-LABEL: define weak_odr void @_ZN7PR101133foo3barIcE3zedEv
642 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN7PR101133foo3barIcE3zedEv
646 template class foo::bar
<zed
>;
647 // CHECK-LABEL: define weak_odr void @_ZN7PR101133foo3barINS_3zedEE3zedEv
648 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN7PR101133foo3barINS_3zedEE3zedEv
652 template<class T
> struct Class
{
656 template class DEFAULT Class
<char>;
657 // CHECK-LABEL: define weak_odr void @_ZNK7PR116905ClassIcE4sizeEv
658 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZNK7PR116905ClassIcE4sizeEv
660 template<class T
> void Method() {}
661 template DEFAULT
void Method
<char>();
662 // CHECK-LABEL: define weak_odr void @_ZN7PR116906MethodIcEEvv
663 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN7PR116906MethodIcEEvv
666 namespace PR11690_2
{
667 namespace foo DEFAULT
{
669 template<typename T1
, typename T2
= bar
>
677 template class foo::zed
<baz
>;
678 // CHECK-LABEL: define weak_odr void @_ZN9PR11690_23foo3zedINS_3bazENS0_3barEE3barEv
679 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN9PR11690_23foo3zedINS_3bazENS0_3barEE3barEv
683 // Having a template argument that is explicitly visible should not make
684 // the template instantiation visible.
685 template <typename T
>
697 // CHECK-LABEL: define linkonce_odr void @_ZN6test231XINS_1AEE1fEv
698 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test231XINS_1AEE1fEv
702 template <typename P1
>
703 void Bind(const P1
& p1
) {
706 class DEFAULT Version
{ };
711 // CHECK-LABEL: define linkonce_odr void @_ZN7PR120014BindINS_7VersionEEEvRKT_
712 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN7PR120014BindINS_7VersionEEEvRKT_
719 template <typename T
>
727 // CHECK-LABEL: define linkonce_odr void @_ZN6test241S3memINS_1AEEEvv
728 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test241S3memINS_1AEEEvv
740 // CHECK-LABEL: define void @_ZN6test261CIiE1fEv
741 // CHECK-HIDDEN-LABEL: define void @_ZN6test261CIiE1fEv
747 static void DEFAULT
baz();
753 // CHECK: declare void @_ZN6test311A1B3bazEv()
754 // CHECK-HIDDEN: declare void @_ZN6test311A1B3bazEv()
765 // CHECK-LABEL: define void @_ZN6test321A1B3bazEv
766 // CHECK-HIDDEN-LABEL: define void @_ZN6test321A1B3bazEv
776 template class DEFAULT foo
<zed
>;
777 // CHECK-LABEL: define weak_odr void @_ZN6test333fooINS_3zedEE3barEv
778 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test333fooINS_3zedEE3barEv
786 template DEFAULT
void bar
<foo
>();
787 // CHECK-LABEL: define weak_odr void @_ZN6test343barINS_3fooEEEvv
788 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test343barINS_3fooEEEvv
792 // This is a really ugly testcase. GCC propagates the DEFAULT in zed's
793 // definition. It's not really clear what we can do here, because we
794 // produce the symbols before even seeing the DEFAULT definition of zed.
795 // FIXME: Maybe the best thing to do here is error? It's certainly hard
796 // to argue that this ought to be valid.
802 template class foo
<zed
>;
805 // CHECK-LABEL: define weak_odr void @_ZN6test353fooINS_3zedEE3barEv
806 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test353fooINS_3zedEE3barEv
810 template<typename T1
, typename T2
>
816 template class foo
<S1
, S2
>;
817 // CHECK-LABEL: define weak_odr hidden void @_ZN6test363fooINS_2S1ENS_2S2EE3barEv
818 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test363fooINS_2S1ENS_2S2EE3barEv
825 DEFAULT
void bar() {}
826 template DEFAULT
void bar
<foo
>();
827 // CHECK-LABEL: define weak_odr void @_ZN6test373barINS_3fooEEEvv
828 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test373barINS_3fooEEEvv
838 template class foo
<zed
>;
839 // CHECK-LABEL: define weak_odr hidden void @_ZN6test383fooINS_3zedEE3barEv
840 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test383fooINS_3zedEE3barEv
844 class DEFAULT default_t
;
845 class HIDDEN hidden_t
;
846 template <class T
> class A
{
847 template <class U
> class B
{
848 HIDDEN
void hidden() {}
850 template <class V
> void temp() {}
853 template class DEFAULT A
<hidden_t
>;
854 template class DEFAULT A
<hidden_t
>::B
<hidden_t
>;
855 template void A
<hidden_t
>::B
<hidden_t
>::temp
<default_t
>();
856 template void A
<hidden_t
>::B
<hidden_t
>::temp
<hidden_t
>();
858 // CHECK-LABEL: define weak_odr hidden void @_ZN6test391AINS_8hidden_tEE1BIS1_E6hiddenEv
859 // CHECK-LABEL: define weak_odr void @_ZN6test391AINS_8hidden_tEE1BIS1_E6noattrEv
860 // CHECK-LABEL: define weak_odr void @_ZN6test391AINS_8hidden_tEE1BIS1_E4tempINS_9default_tEEEvv
862 // GCC produces a default for this one. Why?
863 // CHECK-LABEL: define weak_odr hidden void @_ZN6test391AINS_8hidden_tEE1BIS1_E4tempIS1_EEvv
865 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test391AINS_8hidden_tEE1BIS1_E6hiddenEv
866 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test391AINS_8hidden_tEE1BIS1_E6noattrEv
867 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test391AINS_8hidden_tEE1BIS1_E4tempINS_9default_tEEEvv
869 // GCC produces a default for this one. Why?
870 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test391AINS_8hidden_tEE1BIS1_E4tempIS1_EEvv
880 struct HIDDEN bar
<foo
> {
881 DEFAULT
static void zed();
883 void bar
<foo
>::zed() {
885 // CHECK-LABEL: define void @_ZN6test423barINS_3fooEE3zedEv
886 // CHECK-HIDDEN-LABEL: define void @_ZN6test423barINS_3fooEE3zedEv
896 DEFAULT
void bar
<foo
>() {
898 // CHECK-LABEL: define void @_ZN6test433barINS_3fooEEEvv
899 // CHECK-HIDDEN-LABEL: define void @_ZN6test433barINS_3fooEEEvv
903 template <typename T
>
910 template struct DEFAULT foo
<bar
>;
912 // CHECK-LABEL: define internal void @_ZN6test443fooINS_12_GLOBAL__N_13barEEC1Ev
913 // CHECK-HIDDEN-LABEL: define internal void @_ZN6test443fooINS_12_GLOBAL__N_13barEEC1Ev
917 template <typename T
>
919 template <typename T2
>
927 template struct DEFAULT foo
<int>::bar
<zed
>;
928 foo
<int>::bar
<zed
> x
;
929 // CHECK-LABEL: define internal void @_ZN6test453fooIiE3barINS_12_GLOBAL__N_13zedEEC1Ev
930 // CHECK-HIDDEN-LABEL: define internal void @_ZN6test453fooIiE3barINS_12_GLOBAL__N_13zedEEC1Ev
934 template <typename T
>
940 template DEFAULT
void foo
<bar
>();
944 // CHECK-LABEL: define internal void @_ZN6test463fooINS_12_GLOBAL__N_13barEEEvv
945 // CHECK-HIDDEN-LABEL: define internal void @_ZN6test463fooINS_12_GLOBAL__N_13barEEEvv
950 template <typename T
>
957 template DEFAULT
void foo::bar
<zed
>();
961 // CHECK-LABEL: define internal void @_ZN6test473foo3barINS_12_GLOBAL__N_13zedEEEvv
962 // CHECK-HIDDEN-LABEL: define internal void @_ZN6test473foo3barINS_12_GLOBAL__N_13zedEEEvv
966 // Test that we use the visibility of struct foo when instantiating the
967 // template. Note that is a case where we disagree with gcc, it produces
981 template void bar::zed
<&x
>();
982 // CHECK-LABEL: define weak_odr hidden void @_ZN6test493bar3zedIXadL_ZNS_1xEEEEEvv
983 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test493bar3zedIXadL_ZNS_1xEEEEEvv
987 // Test that we use the visibility of struct foo when instantiating the
988 // template. Note that is a case where we disagree with gcc, it produces
999 template void bar
<&x
>::zed();
1000 // CHECK-LABEL: define weak_odr hidden void @_ZN6test503barIXadL_ZNS_1xEEEE3zedEv
1001 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test503barIXadL_ZNS_1xEEEE3zedEv
1005 // Test that we use the visibility of struct foo when instantiating the
1006 // template. Note that is a case where we disagree with gcc, it produces
1007 // a default symbol.
1009 struct HIDDEN foo
{};
1010 DEFAULT foo da
, db
, dc
, dd
;
1011 HIDDEN foo ha
, hb
, hc
, hd
;
1013 void DEFAULT
zed() {
1015 template void zed
<&da
>();
1016 // CHECK-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2daEEEEEvv(
1017 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2daEEEEEvv(
1019 template void DEFAULT zed
<&db
>();
1020 // CHECK-LABEL: define weak_odr void @_ZN6test513zedIXadL_ZNS_2dbEEEEEvv(
1021 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test513zedIXadL_ZNS_2dbEEEEEvv(
1023 template void HIDDEN zed
<&dc
>();
1024 // CHECK-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2dcEEEEEvv(
1025 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2dcEEEEEvv(
1027 template void zed
<&ha
>();
1028 // CHECK-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2haEEEEEvv(
1029 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2haEEEEEvv(
1031 template void DEFAULT zed
<&hb
>();
1032 // CHECK-LABEL: define weak_odr void @_ZN6test513zedIXadL_ZNS_2hbEEEEEvv(
1033 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test513zedIXadL_ZNS_2hbEEEEEvv(
1035 template void HIDDEN zed
<&hc
>();
1036 // CHECK-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2hcEEEEEvv(
1037 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test513zedIXadL_ZNS_2hcEEEEEvv(
1043 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test513zedIXadL_ZNS_2ddEEEEEvv(
1044 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test513zedIXadL_ZNS_2hdEEEEEvv(
1045 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test513zedIXadL_ZNS_2ddEEEEEvv(
1046 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test513zedIXadL_ZNS_2hdEEEEEvv(
1050 // Test that we use the linkage of struct foo when instantiating the
1051 // template. Note that is a case where we disagree with gcc, it produces
1052 // an external symbol.
1064 // CHECK-LABEL: define internal void @_ZN6test523zedILPNS_12_GLOBAL__N_13fooE0EEEvv
1065 // CHECK-HIDDEN-LABEL: define internal void @_ZN6test523zedILPNS_12_GLOBAL__N_13fooE0EEEvv
1069 template<typename _Tp
> struct vector
{
1070 static void _M_fill_insert();
1072 #pragma GCC visibility push(hidden)
1073 // GCC doesn't seem to use the visibility of enums at all, we do.
1076 // GCC fails to mark this specialization hidden, we mark it.
1078 struct vector
<int> {
1079 static void _M_fill_insert();
1082 vector
<unsigned>::_M_fill_insert();
1083 vector
<int>::_M_fill_insert();
1084 vector
<zed
>::_M_fill_insert();
1086 #pragma GCC visibility pop
1087 // CHECK: declare void @_ZN6test536vectorIjE14_M_fill_insertEv
1088 // CHECK-HIDDEN: declare void @_ZN6test536vectorIjE14_M_fill_insertEv
1089 // CHECK: declare hidden void @_ZN6test536vectorIiE14_M_fill_insertEv
1090 // CHECK-HIDDEN: declare hidden void @_ZN6test536vectorIiE14_M_fill_insertEv
1091 // CHECK: declare hidden void @_ZN6test536vectorINS_3zedEE14_M_fill_insertEv
1092 // CHECK-HIDDEN: declare hidden void @_ZN6test536vectorINS_3zedEE14_M_fill_insertEv
1100 #pragma GCC visibility push(hidden)
1107 #pragma GCC visibility pop
1108 // CHECK: declare hidden void @_ZN6test543fooINS_3zedEE3barEv
1109 // CHECK-HIDDEN: declare hidden void @_ZN6test543fooINS_3zedEE3barEv
1117 template <class T
> struct foo
;
1121 // CHECK: declare hidden void @_ZN6test553fooIiE3barEv
1122 // CHECK-HIDDEN: declare hidden void @_ZN6test553fooIiE3barEv
1126 template <class T
> struct foo
;
1134 // CHECK: declare hidden void @_ZN6test563fooIiE3barEv
1135 // CHECK-HIDDEN: declare hidden void @_ZN6test563fooIiE3barEv
1139 #pragma GCC visibility push(hidden)
1142 void bar(foo
<int>*);
1150 #pragma GCC visibility pop
1151 // CHECK: declare hidden void @_ZN6test573fooIiE3zedEv
1152 // CHECK-HIDDEN: declare hidden void @_ZN6test573fooIiE3zedEv
1156 #pragma GCC visibility push(hidden)
1158 template<typename T
>
1159 struct DEFAULT bar
{
1166 #pragma GCC visibility pop
1167 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test583barINS_3fooEE3zedEv
1168 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test583barINS_3fooEE3zedEv
1174 typedef int (*foo
)();
1175 template<foo x
, foo y
>
1179 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test594testIXadL_ZNS_1gEvEEXadL_ZNS_1fEvEEEEvv
1180 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test594testIXadL_ZNS_1gEvEEXadL_ZNS_1fEvEEEEvv
1183 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test594testIXadL_ZNS_1fEvEEXadL_ZNS_1gEvEEEEvv
1184 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test594testIXadL_ZNS_1fEvEEXadL_ZNS_1gEvEEEEvv
1193 template<template<int> class x
, template<int> class y
>
1197 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test604testINS_1aENS_1bEEEvv
1198 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test604testINS_1aENS_1bEEEvv
1201 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test604testINS_1bENS_1aEEEvv
1202 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test604testINS_1bENS_1aEEEvv
1207 template <typename T1
>
1214 inline void Class1
<int>::f2()
1217 void g(Class1
<int> *x
) {
1222 // Just test that we don't crash. Currently we apply this attribute. Current
1223 // gcc issues a warning about it being unused since "the type is already
1224 // defined". We should probably do the same.
1225 template class HIDDEN Class1
<int>;
1229 template <typename T1
>
1236 inline void Class1
<int>::f2()
1239 void g(Class1
<int> *x
) {
1244 template class HIDDEN Class1
<int>;
1245 // Just test that we don't crash. Currently we apply this attribute. Current
1246 // gcc issues a warning about it being unused since "the type is already
1247 // defined". We should probably do the same.
1251 enum HIDDEN E
{ E0
};
1253 template <E
> static void foo() {}
1255 template <E
> struct B
{
1256 static void foo() {}
1264 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test631A3fooILNS_1EE0EEEvv()
1265 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test631A1BILNS_1EE0EE3fooEv()
1268 // Don't ignore the visibility of template arguments just because we
1269 // explicitly instantiated something.
1272 template <class P
> struct B
{
1273 static DEFAULT
void foo() {}
1276 template class B
<A
>;
1277 // CHECK-LABEL: define weak_odr hidden void @_ZN6test641BINS_1AEE3fooEv()
1282 template <class T
> struct B
{
1284 template <class U
> static void funcT1();
1285 template <class U
> static void funcT2();
1287 template <class U
> class InnerT
{};
1289 template <template <class T
> class Temp
> struct C
{
1290 static void foo() {}
1293 // CHECK-LABEL: define void @_ZN6test651BINS_1AEE4funcEv()
1294 template <> DEFAULT
void B
<A
>::func() {}
1296 // CHECK-LABEL: define void @_ZN6test651BINS_1AEE6funcT2IS1_EEvv()
1297 template <> template <> DEFAULT
void B
<A
>::funcT2
<A
>() {}
1299 // CHECK-LABEL: define linkonce_odr void @_ZN6test651BINS_1AEE6funcT1IiEEvv()
1300 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test651BINS_1AEE6funcT1IS1_EEvv()
1301 template <> template <class T
> DEFAULT
void B
<A
>::funcT1() {}
1303 // CHECK-LABEL: define linkonce_odr void @_ZN6test651BINS_1AEE5Inner3fooEv()
1304 template <> struct DEFAULT B
<A
>::Inner
{
1305 static void foo() {}
1308 // CHECK-LABEL: define linkonce_odr void @_ZN6test651BINS_1AEE6InnerTIiE3fooEv()
1309 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test651BINS_1AEE6InnerTIS1_E3fooEv()
1310 template <> template <class U
> struct DEFAULT B
<A
>::InnerT
{
1311 static void foo() {}
1315 B
<A
>::funcT1
<int>();
1318 B
<A
>::InnerT
<int>::foo();
1319 B
<A
>::InnerT
<A
>::foo();
1322 template class C
<B
<A
>::InnerT
>;
1326 template <typename T
>
1327 struct DEFAULT barT
{
1328 static void zed() {}
1332 template struct barT
<foo
>;
1333 // CHECK-LABEL: define weak_odr void @_ZN6test664barTINS_3fooEE3zedEv
1334 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test664barTINS_3fooEE3zedEv
1337 struct DEFAULT barI
{
1338 static void zed() {}
1341 extern int I DEFAULT
;
1342 template struct barI
<&I
>;
1343 // CHECK-LABEL: define weak_odr void @_ZN6test664barIIXadL_ZNS_1IEEEE3zedEv
1344 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test664barIIXadL_ZNS_1IEEEE3zedEv
1346 typedef void (*fType
)(void);
1348 struct DEFAULT barF
{
1349 static void zed() {}
1353 template struct barF
<F
>;
1354 // CHECK-LABEL: define weak_odr void @_ZN6test664barFIXadL_ZNS_1FEvEEE3zedEv
1355 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test664barFIXadL_ZNS_1FEvEEE3zedEv
1359 template <typename T
>
1360 struct DEFAULT bar
{
1361 static void zed() {}
1366 void f(foo
*rootfoo
);
1370 template struct bar
<foo
>;
1371 // CHECK-LABEL: define weak_odr void @_ZN6test673barINS_3fooEE3zedEv
1372 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test673barINS_3fooEE3zedEv
1376 class A
{ public: ~A(); };
1386 // Check lines at top of file.
1397 namespace foo
__attribute__((visibility("hidden"))) {
1399 // CHECK-LABEL: define void @_ZN6test693foo1fEv
1400 // CHECK-HIDDEN-LABEL: define hidden void @_ZN6test693foo1fEv
1404 // Make sure both the vtable and VTT declarations are marked "hidden"
1408 class HIDDEN B
: virtual A
{
1413 // Check lines at top of file.
1416 // https://github.com/llvm/llvm-project/issues/31462
1420 static HIDDEN T
zed();
1421 template <class U
> HIDDEN U
bar();
1424 T foo
<T
>::zed() { return {}; }
1425 template <class T
> template <class U
>
1426 U foo
<T
>::bar() { return {}; }
1428 extern template struct DEFAULT foo
<int>;
1433 return o
.zed() + o
.bar
<int>() + p
.zed() + p
.bar
<int>();
1435 /// FIXME: foo<int>::bar is hidden in GCC w/ or w/o -fvisibility=hidden.
1436 // CHECK-LABEL: declare hidden noundef i32 @_ZN6test713fooIiE3zedEv(
1437 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZN6test713fooIiE3barIiEET_v(
1438 // CHECK-LABEL: define linkonce_odr hidden noundef i64 @_ZN6test713fooIlE3zedEv(
1439 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZN6test713fooIlE3barIiEET_v(
1440 // CHECK-HIDDEN-LABEL: declare hidden noundef i32 @_ZN6test713fooIiE3zedEv(
1441 // CHECK-HIDDEN-LABEL: define linkonce_odr noundef i32 @_ZN6test713fooIiE3barIiEET_v(
1442 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden noundef i64 @_ZN6test713fooIlE3zedEv(
1443 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden noundef i32 @_ZN6test713fooIlE3barIiEET_v(