blob: a55544573de909397ee918065fef5fb326f74dca [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
Douglas Gregorc66bcfd2010-06-14 23:41:45 +000023// CHECK: @_ZTVN5Test63fooE = weak_odr hidden constant
John McCall1fb0caa2010-10-22 21:05:15 +000024
Anders Carlsson39de84d2010-02-07 01:44:36 +000025namespace Test1 {
26 // CHECK: define hidden void @_ZN5Test11fEv
27 void HIDDEN f() { }
28
29}
30
31namespace Test2 {
32 struct HIDDEN A {
33 void f();
34 };
35
36 // A::f is a member function of a hidden class.
37 // CHECK: define hidden void @_ZN5Test21A1fEv
38 void A::f() { }
39}
40
41namespace Test3 {
42 struct HIDDEN A {
43 struct B {
44 void f();
45 };
46 };
47
48 // B is a nested class where its parent class is hidden.
49 // CHECK: define hidden void @_ZN5Test31A1B1fEv
50 void A::B::f() { }
51}
52
53namespace Test4 HIDDEN {
54 int VariableInHiddenNamespace = 10;
55
56 // Test4::g is in a hidden namespace.
57 // CHECK: define hidden void @_ZN5Test41gEv
58 void g() { }
59
60 struct DEFAULT A {
61 void f();
62 };
63
64 // A has default visibility.
65 // CHECK: define void @_ZN5Test41A1fEv
66 void A::f() { }
67}
68
69namespace Test5 {
70
71 namespace NS HIDDEN {
72 // f is in NS which is hidden.
73 // CHECK: define hidden void @_ZN5Test52NS1fEv()
74 void f() { }
75 }
76
77 namespace NS {
78 // g is in NS, but this NS decl is not hidden.
79 // CHECK: define void @_ZN5Test52NS1gEv
80 void g() { }
81 }
82}
Douglas Gregorc66bcfd2010-06-14 23:41:45 +000083
84// <rdar://problem/8091955>
85namespace Test6 {
86 struct HIDDEN foo {
87 foo() { }
88 void bonk();
89 virtual void bar() = 0;
90
91 virtual void zonk() {}
92 };
93
94 struct barc : public foo {
95 barc();
96 virtual void bar();
97 };
98
99 barc::barc() {}
100}
John McCall1fb0caa2010-10-22 21:05:15 +0000101
102namespace Test7 {
103 class HIDDEN A {};
104 A a; // top of file
105
106 template <A&> struct Aref {
107 static void foo() {}
108 };
109
110 class B : public A {};
111 B b; // top of file
112
113 // CHECK: define linkonce_odr hidden void @_ZN5Test74ArefILZNS_1aEEE3fooEv()
114 void test() {
115 Aref<a>::foo();
116 }
117}
118
119namespace Test8 {
120 void foo();
121 void bar() {}
122 // CHECK-HIDDEN: define hidden void @_ZN5Test83barEv()
123 // CHECK-HIDDEN: declare void @_ZN5Test83fooEv()
124
125 void test() {
126 foo();
127 bar();
128 }
129}
John McCallac65c622010-10-26 04:59:26 +0000130
131// PR8457
132namespace Test9 {
133 extern "C" {
134 struct A { int field; };
135 void DEFAULT test9_fun(struct A *a) { }
136 struct A DEFAULT test9_var; // above
137 }
138 // CHECK: define void @test9_fun(
139 // CHECK-HIDDEN: define void @test9_fun(
140
141 void test() {
142 A a = test9_var;
143 test9_fun(&a);
144 }
145}
John McCall67fa6d52010-10-28 07:07:52 +0000146
147// PR8478
148namespace Test10 {
149 struct A;
150
151 DEFAULT class B {
152 void foo(A*);
153 };
154
155 // CHECK: define void @_ZN6Test101B3fooEPNS_1AE(
156 // CHECK-HIDDEN: define void @_ZN6Test101B3fooEPNS_1AE(
157 void B::foo(A*) {}
158}
John McCall0df95872010-10-29 00:29:13 +0000159
160// PR8492
161namespace Test11 {
162 struct A {
163 void foo() {}
164 void DEFAULT bar() {}
165 };
166
167 void test() {
168 A a;
169 a.foo();
170 a.bar();
171 }
172
173 // CHECK: define linkonce_odr void @_ZN6Test111A3fooEv(
174 // CHECK: define linkonce_odr void @_ZN6Test111A3barEv(
175 // CHECK-HIDDEN: define linkonce_odr hidden void @_ZN6Test111A3fooEv(
176 // CHECK-HIDDEN: define linkonce_odr void @_ZN6Test111A3barEv(
177}
John McCall110e8e52010-10-29 22:22:43 +0000178
179// Tested at top of file.
180namespace Test12 {
181 struct A {
182 // This is hidden in all cases: the explicit attribute takes
183 // priority over -fvisibility on the parent.
184 static int hidden HIDDEN;
185
186 // This is default in all cases because it's only a declaration.
187 static int visible;
188 };
189
190 void test() {
191 A::hidden = 0;
192 A::visible = 0;
193 }
194}
195
196// Tested at top of file.
197namespace Test13 {
198 struct HIDDEN A {};
199
200 // Should be hidden in all cases.
201 struct B {
202 static A a;
203 };
204 A B::a;
205
206 // Should be default in all cases.
207 struct DEFAULT C {
208 static A a;
209 };
210 A C::a;
211};
212
213// Tested at top of file.
214namespace Test14 {
215 // Neither the visibility of the type nor -fvisibility=hidden should
216 // apply to declarations.
217 extern struct A *var;
218
219 struct A *test() { return var; }
220}