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