[Flang] remove whole-archive option for AIX linker (#76039)
[llvm-project.git] / clang / test / CodeGenCXX / visibility.cpp
blobe307b8747c84779fda1d16b91d51d5a88933186d
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")))
11 namespace test30 {
12 // When H is hidden, it should make X hidden, even if the template argument
13 // is not.
14 struct H {
16 template<H *T>
17 struct X {
19 H DEFAULT a;
20 X<&a> b;
21 // CHECK: _ZN6test301bE = global
22 // CHECK-HIDDEN: _ZN6test301bE = hidden global
25 namespace test25 {
26 template<typename T>
27 struct X {
28 template<typename U>
29 struct definition {
33 class DEFAULT A { };
35 X<int>::definition<A> a;
36 // CHECK: @_ZN6test251aE = global
37 // CHECK-HIDDEN: @_ZN6test251aE = hidden global
40 namespace test28 {
41 class DEFAULT foo {
43 foo myvec;
44 // CHECK: @_ZN6test285myvecE = global
45 // CHECK-HIDDEN: @_ZN6test285myvecE = hidden global
48 namespace test29 {
49 #pragma GCC visibility push(hidden)
50 struct RECT {
51 int top;
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
60 namespace test40 {
61 template<typename T>
62 struct foo {
63 DEFAULT static int bar;
65 template<typename T>
66 int foo<T>::bar;
67 template struct foo<int>;
68 // CHECK: _ZN6test403fooIiE3barE = weak_odr global
69 // CHECK-HIDDEN: _ZN6test403fooIiE3barE = weak_odr global
72 namespace test41 {
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
75 // reference to bar.
76 struct HIDDEN foo {};
77 extern foo bar;
78 foo *zed() {
79 return &bar;
81 // CHECK: @_ZN6test413barE = external hidden global
82 // CHECK-HIDDEN: @_ZN6test413barE = external hidden global
85 namespace test48 {
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
88 // a default symbol.
89 struct HIDDEN foo {
91 DEFAULT foo x;
93 struct bar {
94 template<foo *z>
95 struct zed {
99 bar::zed<&x> y;
100 // CHECK: _ZN6test481yE = hidden global
101 // CHECK-HIDDEN: _ZN6test481yE = hidden global
104 namespace test72 {
105 template <class T>
106 struct foo {
107 HIDDEN static int var1;
108 template <class U> HIDDEN static U var2;
110 template <class T> template <class U>
111 U foo<T>::var2;
113 extern template struct DEFAULT foo<int>;
115 int use() {
116 foo<int> o;
117 foo<long> p;
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
126 namespace test73 {
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
179 namespace test27 {
180 template<typename T>
181 class C {
182 class DEFAULT D {
183 void f();
187 template<>
188 class C<int>::D {
189 virtual void g();
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
218 namespace Test1 {
219 // CHECK-LABEL: define hidden void @_ZN5Test11fEv
220 void HIDDEN f() { }
224 namespace Test2 {
225 struct HIDDEN A {
226 void f();
229 // A::f is a member function of a hidden class.
230 // CHECK-LABEL: define hidden void @_ZN5Test21A1fEv
231 void A::f() { }
234 namespace Test3 {
235 struct HIDDEN A {
236 struct B {
237 void f();
241 // B is a nested class where its parent class is hidden.
242 // CHECK-LABEL: define hidden void @_ZN5Test31A1B1fEv
243 void A::B::f() { }
246 namespace Test4 HIDDEN {
247 int VariableInHiddenNamespace = 10;
249 // Test4::g is in a hidden namespace.
250 // CHECK-LABEL: define hidden void @_ZN5Test41gEv
251 void g() { }
253 struct DEFAULT A {
254 void f();
257 // A has default visibility.
258 // CHECK-LABEL: define void @_ZN5Test41A1fEv
259 void A::f() { }
262 namespace Test5 {
264 namespace NS HIDDEN {
265 // f is in NS which is hidden.
266 // CHECK-LABEL: define hidden void @_ZN5Test52NS1fEv()
267 void f() { }
270 namespace NS {
271 // g is in NS, but this NS decl is not hidden.
272 // CHECK-LABEL: define void @_ZN5Test52NS1gEv
273 void g() { }
277 namespace Test6 {
278 struct HIDDEN foo {
279 foo() { }
280 void bonk();
281 virtual void bar() = 0;
283 virtual void zonk() {}
286 struct barc : public foo {
287 barc();
288 virtual void bar();
291 barc::barc() {}
294 namespace Test7 {
295 class HIDDEN A {};
296 A a; // top of file
298 template <A&> struct Aref {
299 static void foo() {}
302 class B : public A {};
303 B b; // top of file
305 // CHECK-LABEL: define linkonce_odr hidden void @_ZN5Test74ArefIL_ZNS_1aEEE3fooEv()
306 void test() {
307 Aref<a>::foo();
311 namespace Test8 {
312 void foo();
313 void bar() {}
314 // CHECK-HIDDEN-LABEL: define hidden void @_ZN5Test83barEv()
315 // CHECK-HIDDEN: declare void @_ZN5Test83fooEv()
317 void test() {
318 foo();
319 bar();
323 // PR8457
324 namespace Test9 {
325 extern "C" {
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(
333 void test() {
334 A a = test9_var;
335 test9_fun(&a);
339 // PR8478
340 namespace Test10 {
341 struct A;
343 class DEFAULT B {
344 void foo(A*);
347 // CHECK-LABEL: define void @_ZN6Test101B3fooEPNS_1AE(
348 // CHECK-HIDDEN-LABEL: define void @_ZN6Test101B3fooEPNS_1AE(
349 void B::foo(A*) {}
352 // PR8492
353 namespace Test11 {
354 struct A {
355 void foo() {}
356 void DEFAULT bar() {}
359 void test() {
360 A a;
361 a.foo();
362 a.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.
372 namespace Test12 {
373 struct A {
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.
379 static int visible;
382 void test() {
383 A::hidden = 0;
384 A::visible = 0;
388 // Tested at top of file.
389 namespace Test13 {
390 struct HIDDEN A {};
392 // Should be hidden in all cases.
393 struct B {
394 static A a;
396 A B::a;
398 // Should be default in all cases.
399 struct DEFAULT C {
400 static A a;
402 A C::a;
405 // Tested at top of file.
406 namespace Test14 {
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; }
414 namespace Test15 {
415 struct A {};
416 template <class T> struct Temp {
417 struct Inner {
418 static char buffer[0];
422 char *test() {
423 return Temp<A>::Inner::buffer;
427 namespace Test16 {
428 struct Base1 { virtual void foo(); };
429 struct Base2 : virtual Base1 { virtual void foo(); };
430 template <class T> struct A : virtual Base1, Base2 {
431 virtual void foo();
433 extern template struct A<char>;
435 void test() {
436 A<char> a;
437 a.foo();
441 namespace Test17 {
442 struct HIDDEN A {
443 static void foo();
444 static void DEFAULT bar();
445 static void HIDDEN baz();
447 struct DEFAULT B {
448 static void foo();
449 static void DEFAULT bar();
450 static void HIDDEN baz();
454 void test() {
455 A::foo();
456 A::bar();
457 A::baz();
458 A::B::foo();
459 A::B::bar();
460 A::B::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()
476 namespace Test18 {
477 template <class T> struct HIDDEN A {
478 static void foo();
479 static void DEFAULT bar();
480 static void HIDDEN baz();
482 struct DEFAULT B {
483 static void foo();
484 static void DEFAULT bar();
485 static void HIDDEN baz();
488 struct HIDDEN H;
490 void test() {
491 A<int>::foo();
492 A<int>::bar();
493 A<int>::baz();
494 A<int>::B::foo();
495 A<int>::B::bar();
496 A<int>::B::baz();
497 A<H>::foo();
498 A<H>::bar();
499 A<H>::baz();
500 A<H>::B::foo();
501 A<H>::B::bar();
502 A<H>::B::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()
530 namespace Test19 {
531 struct A { A(); ~A(); };
533 // Tested at top of file.
534 template <class T> void foo() {
535 static A a;
538 void test() {
539 foo<int>();
543 // Various things with class template specializations.
544 namespace Test20 {
545 template <unsigned> struct HIDDEN A {};
547 // An explicit specialization inherits the explicit visibility of
548 // the template.
549 template <> struct A<0> {
550 static void test0();
551 static void test1();
554 // CHECK-LABEL: define hidden void @_ZN6Test201AILj0EE5test0Ev()
555 void A<0>::test0() {}
557 // CHECK: declare hidden void @_ZN6Test201AILj0EE5test1Ev()
558 void test1() {
559 A<0>::test1();
562 // ...unless that's explicitly overridden.
563 template <> struct DEFAULT A<1> {
564 static void test2();
565 static void test3();
568 // CHECK-LABEL: define void @_ZN6Test201AILj1EE5test2Ev()
569 void A<1>::test2() {}
571 // CHECK: declare void @_ZN6Test201AILj1EE5test3Ev()
572 void test3() {
573 A<1>::test3();
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() {}
580 static void test5();
583 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6Test201BINS_1AILj2EEEE5test4Ev()
584 void test4() {
585 B<A<2> >::test4();
588 // CHECK: declare hidden void @_ZN6Test201BINS_1AILj2EEEE5test5Ev()
589 void test5() {
590 B<A<2> >::test5();
594 // PR9371
595 namespace test21 {
596 enum En { en };
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.
606 namespace test22 {
607 class A1 {};
608 class A2 {};
610 template <class T> struct B {};
611 template <> struct DEFAULT B<A1> {
612 static void foo();
613 static void bar() {}
615 template <> struct B<A2> {
616 static void foo();
617 static void bar() {}
620 void test() {
621 B<A1>::foo();
622 B<A1>::bar();
623 B<A2>::foo();
624 B<A2>::bar();
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()
636 namespace PR10113 {
637 namespace foo DEFAULT {
638 template<typename T>
639 class bar {
640 void zed() {}
643 template class foo::bar<char>;
644 // CHECK-LABEL: define weak_odr void @_ZN7PR101133foo3barIcE3zedEv
645 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN7PR101133foo3barIcE3zedEv
647 struct zed {
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
654 namespace PR11690 {
655 template<class T> struct Class {
656 void size() const {
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 {
671 class bar;
672 template<typename T1, typename T2 = bar>
673 class zed {
674 void bar() {
678 struct baz {
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
685 namespace test23 {
686 // Having a template argument that is explicitly visible should not make
687 // the template instantiation visible.
688 template <typename T>
689 struct X {
690 static void f() {
694 class DEFAULT A;
696 void g() {
697 X<A> y;
698 y.f();
700 // CHECK-LABEL: define linkonce_odr void @_ZN6test231XINS_1AEE1fEv
701 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test231XINS_1AEE1fEv
704 namespace PR12001 {
705 template <typename P1>
706 void Bind(const P1& p1) {
709 class DEFAULT Version { };
711 void f() {
712 Bind(Version());
714 // CHECK-LABEL: define linkonce_odr void @_ZN7PR120014BindINS_7VersionEEEvRKT_
715 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN7PR120014BindINS_7VersionEEEvRKT_
718 namespace test24 {
719 class DEFAULT A { };
721 struct S {
722 template <typename T>
723 void mem() {}
726 void test() {
727 S s;
728 s.mem<A>();
730 // CHECK-LABEL: define linkonce_odr void @_ZN6test241S3memINS_1AEEEvv
731 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test241S3memINS_1AEEEvv
734 namespace test26 {
735 template<typename T>
736 class C {
737 DEFAULT void f();
740 template<>
741 void C<int>::f() { }
743 // CHECK-LABEL: define void @_ZN6test261CIiE1fEv
744 // CHECK-HIDDEN-LABEL: define void @_ZN6test261CIiE1fEv
747 namespace test31 {
748 struct A {
749 struct HIDDEN B {
750 static void DEFAULT baz();
753 void f() {
754 A::B::baz();
756 // CHECK: declare void @_ZN6test311A1B3bazEv()
757 // CHECK-HIDDEN: declare void @_ZN6test311A1B3bazEv()
760 namespace test32 {
761 struct HIDDEN A {
762 struct DEFAULT B {
763 void DEFAULT baz();
766 void A::B::baz() {
768 // CHECK-LABEL: define void @_ZN6test321A1B3bazEv
769 // CHECK-HIDDEN-LABEL: define void @_ZN6test321A1B3bazEv
772 namespace test33 {
773 template<typename T>
774 class foo {
775 void bar() {}
777 struct HIDDEN zed {
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
784 namespace test34 {
785 struct foo {
787 template<class T>
788 void bar() {}
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
794 namespace test35 {
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.
800 template<typename T>
801 struct DEFAULT foo {
802 void bar() {}
804 class zed;
805 template class foo<zed>;
806 class DEFAULT zed {
808 // CHECK-LABEL: define weak_odr void @_ZN6test353fooINS_3zedEE3barEv
809 // CHECK-HIDDEN-LABEL: define weak_odr hidden void @_ZN6test353fooINS_3zedEE3barEv
812 namespace test36 {
813 template<typename T1, typename T2>
814 class foo {
815 void bar() {}
817 class DEFAULT S1 {};
818 struct HIDDEN S2 {};
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
824 namespace test37 {
825 struct HIDDEN foo {
827 template<class T>
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
834 namespace test38 {
835 template<typename T>
836 class DEFAULT foo {
837 void bar() {}
839 struct HIDDEN zed {
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
846 namespace test39 {
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() {}
852 void noattr() {}
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
876 namespace test42 {
877 struct HIDDEN foo {
879 template <class P>
880 struct bar {
882 template <>
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
892 namespace test43 {
893 struct HIDDEN foo {
895 template <class P>
896 void bar() {
898 template <>
899 DEFAULT void bar<foo>() {
901 // CHECK-LABEL: define void @_ZN6test433barINS_3fooEEEvv
902 // CHECK-HIDDEN-LABEL: define void @_ZN6test433barINS_3fooEEEvv
905 namespace test44 {
906 template <typename T>
907 struct foo {
908 foo() {}
910 namespace {
911 struct bar;
913 template struct DEFAULT foo<bar>;
914 foo<bar> x;
915 // CHECK-LABEL: define internal void @_ZN6test443fooINS_12_GLOBAL__N_13barEEC1Ev
916 // CHECK-HIDDEN-LABEL: define internal void @_ZN6test443fooINS_12_GLOBAL__N_13barEEC1Ev
919 namespace test45 {
920 template <typename T>
921 struct foo {
922 template <typename T2>
923 struct bar {
924 bar() {};
927 namespace {
928 struct zed;
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
936 namespace test46 {
937 template <typename T>
938 void foo() {
940 namespace {
941 struct bar;
943 template DEFAULT void foo<bar>();
944 void zed() {
945 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
951 namespace test47 {
952 struct foo {
953 template <typename T>
954 static void bar() {
957 namespace {
958 struct zed;
960 template DEFAULT void foo::bar<zed>();
961 void baz() {
962 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
968 namespace test49 {
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
971 // a default symbol.
973 struct HIDDEN foo {
976 DEFAULT foo x;
978 struct bar {
979 template<foo *z>
980 void zed() {
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
989 namespace test50 {
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
992 // a default symbol.
994 struct HIDDEN foo {
996 DEFAULT foo x;
997 template<foo *z>
998 struct DEFAULT bar {
999 void zed() {
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
1007 namespace test51 {
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;
1015 template<foo *z>
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(
1054 void use() {
1055 zed<&df>();
1056 zed<&hf>();
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(
1064 namespace test52 {
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.
1069 namespace {
1070 struct foo {
1073 template<foo *x>
1074 void zed() {
1076 void f() {
1077 zed<nullptr>();
1079 // CHECK-LABEL: define internal void @_ZN6test523zedILPNS_12_GLOBAL__N_13fooE0EEEvv
1080 // CHECK-HIDDEN-LABEL: define internal void @_ZN6test523zedILPNS_12_GLOBAL__N_13fooE0EEEvv
1083 namespace test53 {
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.
1089 enum zed {v1};
1091 // GCC fails to mark this specialization hidden, we mark it.
1092 template<>
1093 struct vector<int> {
1094 static void _M_fill_insert();
1096 void foo() {
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
1110 namespace test54 {
1111 template <class T>
1112 struct foo {
1113 static void bar();
1115 #pragma GCC visibility push(hidden)
1116 class zed {
1117 zed(const zed &);
1119 void bah() {
1120 foo<zed>::bar();
1122 #pragma GCC visibility pop
1123 // CHECK: declare hidden void @_ZN6test543fooINS_3zedEE3barEv
1124 // CHECK-HIDDEN: declare hidden void @_ZN6test543fooINS_3zedEE3barEv
1127 namespace test55 {
1128 template <class T>
1129 struct HIDDEN foo {
1130 static void bar();
1132 template <class T> struct foo;
1133 void foobar() {
1134 foo<int>::bar();
1136 // CHECK: declare hidden void @_ZN6test553fooIiE3barEv
1137 // CHECK-HIDDEN: declare hidden void @_ZN6test553fooIiE3barEv
1140 namespace test56 {
1141 template <class T> struct foo;
1142 template <class T>
1143 struct HIDDEN foo {
1144 static void bar();
1146 void foobar() {
1147 foo<int>::bar();
1149 // CHECK: declare hidden void @_ZN6test563fooIiE3barEv
1150 // CHECK-HIDDEN: declare hidden void @_ZN6test563fooIiE3barEv
1153 namespace test57 {
1154 #pragma GCC visibility push(hidden)
1155 template <class T>
1156 struct foo;
1157 void bar(foo<int>*);
1158 template <class T>
1159 struct foo {
1160 static void zed();
1162 void bah() {
1163 foo<int>::zed();
1165 #pragma GCC visibility pop
1166 // CHECK: declare hidden void @_ZN6test573fooIiE3zedEv
1167 // CHECK-HIDDEN: declare hidden void @_ZN6test573fooIiE3zedEv
1170 namespace test58 {
1171 #pragma GCC visibility push(hidden)
1172 struct foo;
1173 template<typename T>
1174 struct DEFAULT bar {
1175 static void zed() {
1178 void bah() {
1179 bar<foo>::zed();
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
1186 namespace test59 {
1187 DEFAULT int f();
1188 HIDDEN int g();
1189 typedef int (*foo)();
1190 template<foo x, foo y>
1191 void test() {}
1192 void use() {
1193 test<&g, &f>();
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
1197 test<&f, &g>();
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
1203 namespace test60 {
1204 template<int i>
1205 class HIDDEN a {};
1206 template<int i>
1207 class DEFAULT b {};
1208 template<template<int> class x, template<int> class y>
1209 void test() {}
1210 void use() {
1211 test<a, b>();
1212 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test604testINS_1aENS_1bEEEvv
1213 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test604testINS_1aENS_1bEEEvv
1215 test<b, a>();
1216 // CHECK-LABEL: define linkonce_odr hidden void @_ZN6test604testINS_1bENS_1aEEEvv
1217 // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void @_ZN6test604testINS_1bENS_1aEEEvv
1221 namespace test61 {
1222 template <typename T1>
1223 struct Class1
1225 void f1() { f2(); }
1226 inline void f2();
1228 template<>
1229 inline void Class1<int>::f2()
1232 void g(Class1<int> *x) {
1233 x->f1();
1236 namespace test61 {
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>;
1243 namespace test62 {
1244 template <typename T1>
1245 struct Class1
1247 void f1() { f2(); }
1248 inline void f2() {}
1250 template<>
1251 inline void Class1<int>::f2()
1254 void g(Class1<int> *x) {
1255 x->f2();
1258 namespace test62 {
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.
1265 namespace test63 {
1266 enum HIDDEN E { E0 };
1267 struct A {
1268 template <E> static void foo() {}
1270 template <E> struct B {
1271 static void foo() {}
1275 void test() {
1276 A::foo<E0>();
1277 A::B<E0>::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.
1285 namespace test64 {
1286 struct HIDDEN A {};
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()
1295 namespace test65 {
1296 class HIDDEN A {};
1297 template <class T> struct B {
1298 static void func();
1299 template <class U> static void funcT1();
1300 template <class U> static void funcT2();
1301 class Inner {};
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() {}
1329 void test() {
1330 B<A>::funcT1<int>();
1331 B<A>::funcT1<A>();
1332 B<A>::Inner::foo();
1333 B<A>::InnerT<int>::foo();
1334 B<A>::InnerT<A>::foo();
1337 template class C<B<A>::InnerT>;
1340 namespace test66 {
1341 template <typename T>
1342 struct DEFAULT barT {
1343 static void zed() {}
1345 class foo;
1346 class DEFAULT foo;
1347 template struct barT<foo>;
1348 // CHECK-LABEL: define weak_odr void @_ZN6test664barTINS_3fooEE3zedEv
1349 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test664barTINS_3fooEE3zedEv
1351 template <int* I>
1352 struct DEFAULT barI {
1353 static void zed() {}
1355 extern int I;
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);
1362 template<fType F>
1363 struct DEFAULT barF {
1364 static void zed() {}
1366 void F();
1367 void F() DEFAULT;
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
1373 namespace test67 {
1374 template <typename T>
1375 struct DEFAULT bar {
1376 static void zed() {}
1379 class foo;
1380 class compute {
1381 void f(foo *rootfoo);
1383 class DEFAULT foo;
1385 template struct bar<foo>;
1386 // CHECK-LABEL: define weak_odr void @_ZN6test673barINS_3fooEE3zedEv
1387 // CHECK-HIDDEN-LABEL: define weak_odr void @_ZN6test673barINS_3fooEE3zedEv
1390 namespace test68 {
1391 class A { public: ~A(); };
1392 class f {
1393 public:
1394 f() {
1395 static A test;
1398 void g() {
1399 f a;
1401 // Check lines at top of file.
1404 namespace test69 {
1405 // PR18174
1406 namespace foo {
1407 void f();
1409 namespace foo {
1410 void f() {};
1412 namespace foo __attribute__((visibility("hidden"))) {
1414 // CHECK-LABEL: define void @_ZN6test693foo1fEv
1415 // CHECK-HIDDEN-LABEL: define hidden void @_ZN6test693foo1fEv
1418 namespace test70 {
1419 // Make sure both the vtable and VTT declarations are marked "hidden"
1420 class HIDDEN A {
1421 virtual void a();
1423 class HIDDEN B : virtual A {
1424 void a() override;
1425 ~B();
1427 B::~B() {}
1429 // Make sure both the vtable and VTT declarations are marked "hidden"
1430 // when "-fvisibilty=hidden" is in use.
1431 class C {};
1432 class D : virtual C {};
1433 D d;
1434 // Check lines at top of file.
1437 // https://github.com/llvm/llvm-project/issues/31462
1438 namespace test71 {
1439 template <class T>
1440 struct foo {
1441 static HIDDEN T zed();
1442 template <class U> HIDDEN U bar();
1444 template <class T>
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>;
1451 int use() {
1452 foo<int> o;
1453 foo<long> p;
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(