Anders Carlsson | 39de84d | 2010-02-07 01:44:36 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -fvisibility hidden -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-HIDDEN |
Anders Carlsson | 39de84d | 2010-02-07 01:44:36 +0000 | [diff] [blame] | 3 | |
| 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 McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 9 | // CHECK: @_ZN5Test71aE = hidden global |
| 10 | // CHECK: @_ZN5Test71bE = global |
John McCall | ac65c62 | 2010-10-26 04:59:26 +0000 | [diff] [blame] | 11 | // CHECK: @test9_var = global |
| 12 | // CHECK-HIDDEN: @test9_var = global |
John McCall | 110e8e5 | 2010-10-29 22:22:43 +0000 | [diff] [blame] | 13 | // 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 McCall | ee30102 | 2010-10-30 09:18:49 +0000 | [diff] [blame^] | 23 | // CHECK: @_ZN6Test154TempINS_1AEE5Inner6bufferE = external global [0 x i8] |
| 24 | // CHECK-HIDDEN: @_ZN6Test154TempINS_1AEE5Inner6bufferE = external global [0 x i8] |
Douglas Gregor | c66bcfd | 2010-06-14 23:41:45 +0000 | [diff] [blame] | 25 | // CHECK: @_ZTVN5Test63fooE = weak_odr hidden constant |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 26 | |
Anders Carlsson | 39de84d | 2010-02-07 01:44:36 +0000 | [diff] [blame] | 27 | namespace Test1 { |
| 28 | // CHECK: define hidden void @_ZN5Test11fEv |
| 29 | void HIDDEN f() { } |
| 30 | |
| 31 | } |
| 32 | |
| 33 | namespace 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 | |
| 43 | namespace 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 | |
| 55 | namespace 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 | |
| 71 | namespace 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 Gregor | c66bcfd | 2010-06-14 23:41:45 +0000 | [diff] [blame] | 85 | |
| 86 | // <rdar://problem/8091955> |
| 87 | namespace 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 McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 103 | |
| 104 | namespace 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 | |
| 121 | namespace 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 McCall | ac65c62 | 2010-10-26 04:59:26 +0000 | [diff] [blame] | 132 | |
| 133 | // PR8457 |
| 134 | namespace 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 McCall | 67fa6d5 | 2010-10-28 07:07:52 +0000 | [diff] [blame] | 148 | |
| 149 | // PR8478 |
| 150 | namespace 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 McCall | 0df9587 | 2010-10-29 00:29:13 +0000 | [diff] [blame] | 161 | |
| 162 | // PR8492 |
| 163 | namespace 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 McCall | 110e8e5 | 2010-10-29 22:22:43 +0000 | [diff] [blame] | 180 | |
| 181 | // Tested at top of file. |
| 182 | namespace 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. |
| 199 | namespace 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. |
| 216 | namespace 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 McCall | ee30102 | 2010-10-30 09:18:49 +0000 | [diff] [blame^] | 223 | |
| 224 | // rdar://problem/8613093 |
| 225 | namespace 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 | } |