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 |
Douglas Gregor | c66bcfd | 2010-06-14 23:41:45 +0000 | [diff] [blame] | 23 | // CHECK: @_ZTVN5Test63fooE = weak_odr hidden constant |
John McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 24 | |
Anders Carlsson | 39de84d | 2010-02-07 01:44:36 +0000 | [diff] [blame] | 25 | namespace Test1 { |
| 26 | // CHECK: define hidden void @_ZN5Test11fEv |
| 27 | void HIDDEN f() { } |
| 28 | |
| 29 | } |
| 30 | |
| 31 | namespace 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 | |
| 41 | namespace 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 | |
| 53 | namespace 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 | |
| 69 | namespace 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 Gregor | c66bcfd | 2010-06-14 23:41:45 +0000 | [diff] [blame] | 83 | |
| 84 | // <rdar://problem/8091955> |
| 85 | namespace 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 McCall | 1fb0caa | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 101 | |
| 102 | namespace 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 | |
| 119 | namespace 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 McCall | ac65c62 | 2010-10-26 04:59:26 +0000 | [diff] [blame] | 130 | |
| 131 | // PR8457 |
| 132 | namespace 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 McCall | 67fa6d5 | 2010-10-28 07:07:52 +0000 | [diff] [blame] | 146 | |
| 147 | // PR8478 |
| 148 | namespace 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 McCall | 0df9587 | 2010-10-29 00:29:13 +0000 | [diff] [blame] | 159 | |
| 160 | // PR8492 |
| 161 | namespace 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 McCall | 110e8e5 | 2010-10-29 22:22:43 +0000 | [diff] [blame] | 178 | |
| 179 | // Tested at top of file. |
| 180 | namespace 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. |
| 197 | namespace 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. |
| 214 | namespace 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 | } |