blob: 2272d1fa5e4f0325dcbf9b96f9051cc22d92afe9 [file] [log] [blame]
Anders Carlsson39de84d2010-02-07 01:44:36 +00001// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
John McCall1fb0caa2010-10-22 21:05:15 +00002// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -fvisibility hidden -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-HIDDEN
Anders Carlsson39de84d2010-02-07 01:44:36 +00003
4#define HIDDEN __attribute__((visibility("hidden")))
5#define PROTECTED __attribute__((visibility("protected")))
6#define DEFAULT __attribute__((visibility("default")))
7
8// CHECK: @_ZN5Test425VariableInHiddenNamespaceE = hidden global i32 10
John McCall1fb0caa2010-10-22 21:05:15 +00009// CHECK: @_ZN5Test71aE = hidden global
10// CHECK: @_ZN5Test71bE = global
John McCallac65c622010-10-26 04:59:26 +000011// CHECK: @test9_var = global
12// CHECK-HIDDEN: @test9_var = global
John McCall110e8e52010-10-29 22:22:43 +000013// CHECK: @_ZN6Test121A6hiddenE = external hidden global
14// CHECK: @_ZN6Test121A7visibleE = external global
15// CHECK-HIDDEN: @_ZN6Test121A6hiddenE = external hidden global
16// CHECK-HIDDEN: @_ZN6Test121A7visibleE = external global
17// CHECK: @_ZN6Test131B1aE = hidden global
18// CHECK: @_ZN6Test131C1aE = global
19// CHECK-HIDDEN: @_ZN6Test131B1aE = hidden global
20// CHECK-HIDDEN: @_ZN6Test131C1aE = global
21// CHECK: @_ZN6Test143varE = external global
22// CHECK-HIDDEN: @_ZN6Test143varE = external global
John McCallee301022010-10-30 09:18:49 +000023// CHECK: @_ZN6Test154TempINS_1AEE5Inner6bufferE = external global [0 x i8]
24// CHECK-HIDDEN: @_ZN6Test154TempINS_1AEE5Inner6bufferE = external global [0 x i8]
Douglas Gregorc66bcfd2010-06-14 23:41:45 +000025// CHECK: @_ZTVN5Test63fooE = weak_odr hidden constant
John McCall1fb0caa2010-10-22 21:05:15 +000026
Anders Carlsson39de84d2010-02-07 01:44:36 +000027namespace Test1 {
28 // CHECK: define hidden void @_ZN5Test11fEv
29 void HIDDEN f() { }
30
31}
32
33namespace Test2 {
34 struct HIDDEN A {
35 void f();
36 };
37
38 // A::f is a member function of a hidden class.
39 // CHECK: define hidden void @_ZN5Test21A1fEv
40 void A::f() { }
41}
42
43namespace Test3 {
44 struct HIDDEN A {
45 struct B {
46 void f();
47 };
48 };
49
50 // B is a nested class where its parent class is hidden.
51 // CHECK: define hidden void @_ZN5Test31A1B1fEv
52 void A::B::f() { }
53}
54
55namespace Test4 HIDDEN {
56 int VariableInHiddenNamespace = 10;
57
58 // Test4::g is in a hidden namespace.
59 // CHECK: define hidden void @_ZN5Test41gEv
60 void g() { }
61
62 struct DEFAULT A {
63 void f();
64 };
65
66 // A has default visibility.
67 // CHECK: define void @_ZN5Test41A1fEv
68 void A::f() { }
69}
70
71namespace Test5 {
72
73 namespace NS HIDDEN {
74 // f is in NS which is hidden.
75 // CHECK: define hidden void @_ZN5Test52NS1fEv()
76 void f() { }
77 }
78
79 namespace NS {
80 // g is in NS, but this NS decl is not hidden.
81 // CHECK: define void @_ZN5Test52NS1gEv
82 void g() { }
83 }
84}
Douglas Gregorc66bcfd2010-06-14 23:41:45 +000085
86// <rdar://problem/8091955>
87namespace Test6 {
88 struct HIDDEN foo {
89 foo() { }
90 void bonk();
91 virtual void bar() = 0;
92
93 virtual void zonk() {}
94 };
95
96 struct barc : public foo {
97 barc();
98 virtual void bar();
99 };
100
101 barc::barc() {}
102}
John McCall1fb0caa2010-10-22 21:05:15 +0000103
104namespace Test7 {
105 class HIDDEN A {};
106 A a; // top of file
107
108 template <A&> struct Aref {
109 static void foo() {}
110 };
111
112 class B : public A {};
113 B b; // top of file
114
115 // CHECK: define linkonce_odr hidden void @_ZN5Test74ArefILZNS_1aEEE3fooEv()
116 void test() {
117 Aref<a>::foo();
118 }
119}
120
121namespace Test8 {
122 void foo();
123 void bar() {}
124 // CHECK-HIDDEN: define hidden void @_ZN5Test83barEv()
125 // CHECK-HIDDEN: declare void @_ZN5Test83fooEv()
126
127 void test() {
128 foo();
129 bar();
130 }
131}
John McCallac65c622010-10-26 04:59:26 +0000132
133// PR8457
134namespace Test9 {
135 extern "C" {
136 struct A { int field; };
137 void DEFAULT test9_fun(struct A *a) { }
138 struct A DEFAULT test9_var; // above
139 }
140 // CHECK: define void @test9_fun(
141 // CHECK-HIDDEN: define void @test9_fun(
142
143 void test() {
144 A a = test9_var;
145 test9_fun(&a);
146 }
147}
John McCall67fa6d52010-10-28 07:07:52 +0000148
149// PR8478
150namespace Test10 {
151 struct A;
152
153 DEFAULT class B {
154 void foo(A*);
155 };
156
157 // CHECK: define void @_ZN6Test101B3fooEPNS_1AE(
158 // CHECK-HIDDEN: define void @_ZN6Test101B3fooEPNS_1AE(
159 void B::foo(A*) {}
160}
John McCall0df95872010-10-29 00:29:13 +0000161
162// PR8492
163namespace Test11 {
164 struct A {
165 void foo() {}
166 void DEFAULT bar() {}
167 };
168
169 void test() {
170 A a;
171 a.foo();
172 a.bar();
173 }
174
175 // CHECK: define linkonce_odr void @_ZN6Test111A3fooEv(
176 // CHECK: define linkonce_odr void @_ZN6Test111A3barEv(
177 // CHECK-HIDDEN: define linkonce_odr hidden void @_ZN6Test111A3fooEv(
178 // CHECK-HIDDEN: define linkonce_odr void @_ZN6Test111A3barEv(
179}
John McCall110e8e52010-10-29 22:22:43 +0000180
181// Tested at top of file.
182namespace Test12 {
183 struct A {
184 // This is hidden in all cases: the explicit attribute takes
185 // priority over -fvisibility on the parent.
186 static int hidden HIDDEN;
187
188 // This is default in all cases because it's only a declaration.
189 static int visible;
190 };
191
192 void test() {
193 A::hidden = 0;
194 A::visible = 0;
195 }
196}
197
198// Tested at top of file.
199namespace Test13 {
200 struct HIDDEN A {};
201
202 // Should be hidden in all cases.
203 struct B {
204 static A a;
205 };
206 A B::a;
207
208 // Should be default in all cases.
209 struct DEFAULT C {
210 static A a;
211 };
212 A C::a;
213};
214
215// Tested at top of file.
216namespace Test14 {
217 // Neither the visibility of the type nor -fvisibility=hidden should
218 // apply to declarations.
219 extern struct A *var;
220
221 struct A *test() { return var; }
222}
John McCallee301022010-10-30 09:18:49 +0000223
224// rdar://problem/8613093
225namespace Test15 {
226 struct A {};
227 template <class T> struct Temp {
228 struct Inner {
229 static char buffer[0];
230 };
231 };
232
233 char *test() {
234 return Temp<A>::Inner::buffer;
235 }
236}