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