xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/visibility-ms-compat.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -std=c++11 -triple=x86_64-apple-darwin10 -fvisibility hidden -ftype-visibility default -emit-llvm -o %t
2*f4a2713aSLionel Sambuc // RUN: FileCheck %s < %t
3*f4a2713aSLionel Sambuc // RUN: FileCheck -check-prefix=CHECK-GLOBAL %s < %t
4*f4a2713aSLionel Sambuc 
5*f4a2713aSLionel Sambuc // The two visibility options above are how we translate
6*f4a2713aSLionel Sambuc // -fvisibility-ms-compat in the driver.
7*f4a2713aSLionel Sambuc 
8*f4a2713aSLionel Sambuc // rdar://13079314
9*f4a2713aSLionel Sambuc 
10*f4a2713aSLionel Sambuc #define HIDDEN __attribute__((visibility("hidden")))
11*f4a2713aSLionel Sambuc #define PROTECTED __attribute__((visibility("protected")))
12*f4a2713aSLionel Sambuc #define DEFAULT __attribute__((visibility("default")))
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc namespace std {
15*f4a2713aSLionel Sambuc   class type_info;
16*f4a2713aSLionel Sambuc };
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc namespace test0 {
19*f4a2713aSLionel Sambuc   struct A {
20*f4a2713aSLionel Sambuc     static void foo();
21*f4a2713aSLionel Sambuc     static void bar();
22*f4a2713aSLionel Sambuc   };
23*f4a2713aSLionel Sambuc 
24*f4a2713aSLionel Sambuc   void A::foo() { bar(); }
25*f4a2713aSLionel Sambuc   // CHECK-LABEL: define hidden void @_ZN5test01A3fooEv()
26*f4a2713aSLionel Sambuc   // CHECK: declare void @_ZN5test01A3barEv()
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc   const std::type_info &ti = typeid(A);
29*f4a2713aSLionel Sambuc   // CHECK-GLOBAL: @_ZTSN5test01AE = linkonce_odr constant
30*f4a2713aSLionel Sambuc   // CHECK-GLOBAL: @_ZTIN5test01AE = linkonce_odr unnamed_addr constant
31*f4a2713aSLionel Sambuc   // CHECK-GLOBAL: @_ZN5test02tiE = hidden constant
32*f4a2713aSLionel Sambuc }
33*f4a2713aSLionel Sambuc 
34*f4a2713aSLionel Sambuc namespace test1 {
35*f4a2713aSLionel Sambuc   struct HIDDEN A {
36*f4a2713aSLionel Sambuc     static void foo();
37*f4a2713aSLionel Sambuc     static void bar();
38*f4a2713aSLionel Sambuc   };
39*f4a2713aSLionel Sambuc 
40*f4a2713aSLionel Sambuc   void A::foo() { bar(); }
41*f4a2713aSLionel Sambuc   // CHECK-LABEL: define hidden void @_ZN5test11A3fooEv()
42*f4a2713aSLionel Sambuc   // CHECK: declare hidden void @_ZN5test11A3barEv()
43*f4a2713aSLionel Sambuc 
44*f4a2713aSLionel Sambuc   const std::type_info &ti = typeid(A);
45*f4a2713aSLionel Sambuc   // CHECK-GLOBAL: @_ZTSN5test11AE = linkonce_odr hidden constant
46*f4a2713aSLionel Sambuc   // CHECK-GLOBAL: @_ZTIN5test11AE = linkonce_odr hidden unnamed_addr constant
47*f4a2713aSLionel Sambuc   // CHECK-GLOBAL: @_ZN5test12tiE = hidden constant
48*f4a2713aSLionel Sambuc }
49*f4a2713aSLionel Sambuc 
50*f4a2713aSLionel Sambuc namespace test2 {
51*f4a2713aSLionel Sambuc   struct DEFAULT A {
52*f4a2713aSLionel Sambuc     static void foo();
53*f4a2713aSLionel Sambuc     static void bar();
54*f4a2713aSLionel Sambuc   };
55*f4a2713aSLionel Sambuc 
56*f4a2713aSLionel Sambuc   void A::foo() { bar(); }
57*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN5test21A3fooEv()
58*f4a2713aSLionel Sambuc   // CHECK: declare void @_ZN5test21A3barEv()
59*f4a2713aSLionel Sambuc 
60*f4a2713aSLionel Sambuc   const std::type_info &ti = typeid(A);
61*f4a2713aSLionel Sambuc   // CHECK-GLOBAL: @_ZTSN5test21AE = linkonce_odr constant
62*f4a2713aSLionel Sambuc   // CHECK-GLOBAL: @_ZTIN5test21AE = linkonce_odr unnamed_addr constant
63*f4a2713aSLionel Sambuc   // CHECK-GLOBAL: @_ZN5test22tiE = hidden constant
64*f4a2713aSLionel Sambuc }
65*f4a2713aSLionel Sambuc 
66*f4a2713aSLionel Sambuc namespace test3 {
67*f4a2713aSLionel Sambuc   struct A { int x; };
68*f4a2713aSLionel Sambuc   template <class T> struct B {
69*f4a2713aSLionel Sambuc     static void foo() { bar(); }
70*f4a2713aSLionel Sambuc     static void bar();
71*f4a2713aSLionel Sambuc   };
72*f4a2713aSLionel Sambuc 
73*f4a2713aSLionel Sambuc   template void B<A>::foo();
74*f4a2713aSLionel Sambuc   // CHECK-LABEL: define weak_odr hidden void @_ZN5test31BINS_1AEE3fooEv()
75*f4a2713aSLionel Sambuc   // CHECK: declare void @_ZN5test31BINS_1AEE3barEv()
76*f4a2713aSLionel Sambuc 
77*f4a2713aSLionel Sambuc   const std::type_info &ti = typeid(B<A>);
78*f4a2713aSLionel Sambuc   // CHECK-GLOBAL: @_ZTSN5test31BINS_1AEEE = linkonce_odr constant
79*f4a2713aSLionel Sambuc   // CHECK-GLOBAL: @_ZTIN5test31BINS_1AEEE = linkonce_odr unnamed_addr constant
80*f4a2713aSLionel Sambuc }
81*f4a2713aSLionel Sambuc 
82*f4a2713aSLionel Sambuc namespace test4 {
83*f4a2713aSLionel Sambuc   struct A { int x; };
84*f4a2713aSLionel Sambuc   template <class T> struct DEFAULT B {
85*f4a2713aSLionel Sambuc     static void foo() { bar(); }
86*f4a2713aSLionel Sambuc     static void bar();
87*f4a2713aSLionel Sambuc   };
88*f4a2713aSLionel Sambuc 
89*f4a2713aSLionel Sambuc   template void B<A>::foo();
90*f4a2713aSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5test41BINS_1AEE3fooEv()
91*f4a2713aSLionel Sambuc   // CHECK: declare void @_ZN5test41BINS_1AEE3barEv()
92*f4a2713aSLionel Sambuc 
93*f4a2713aSLionel Sambuc   const std::type_info &ti = typeid(B<A>);
94*f4a2713aSLionel Sambuc   // CHECK-GLOBAL: @_ZTSN5test41BINS_1AEEE = linkonce_odr constant
95*f4a2713aSLionel Sambuc   // CHECK-GLOBAL: @_ZTIN5test41BINS_1AEEE = linkonce_odr unnamed_addr constant
96*f4a2713aSLionel Sambuc }
97*f4a2713aSLionel Sambuc 
98*f4a2713aSLionel Sambuc namespace test5 {
99*f4a2713aSLionel Sambuc   struct A { int x; };
100*f4a2713aSLionel Sambuc   template <class T> struct HIDDEN B {
101*f4a2713aSLionel Sambuc     static void foo() { bar(); }
102*f4a2713aSLionel Sambuc     static void bar();
103*f4a2713aSLionel Sambuc   };
104*f4a2713aSLionel Sambuc 
105*f4a2713aSLionel Sambuc   template void B<A>::foo();
106*f4a2713aSLionel Sambuc   // CHECK-LABEL: define weak_odr hidden void @_ZN5test51BINS_1AEE3fooEv()
107*f4a2713aSLionel Sambuc   // CHECK: declare hidden void @_ZN5test51BINS_1AEE3barEv()
108*f4a2713aSLionel Sambuc 
109*f4a2713aSLionel Sambuc   const std::type_info &ti = typeid(B<A>);
110*f4a2713aSLionel Sambuc   // CHECK-GLOBAL: @_ZTSN5test51BINS_1AEEE = linkonce_odr hidden constant
111*f4a2713aSLionel Sambuc   // CHECK-GLOBAL: @_ZTIN5test51BINS_1AEEE = linkonce_odr hidden unnamed_addr constant
112*f4a2713aSLionel Sambuc }
113