blob: 0eb075c999d7447a020c809e62290f560d639c00 [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
Douglas Gregorc66bcfd2010-06-14 23:41:45 +000011// CHECK: @_ZTVN5Test63fooE = weak_odr hidden constant
John McCall1fb0caa2010-10-22 21:05:15 +000012
Anders Carlsson39de84d2010-02-07 01:44:36 +000013namespace Test1 {
14 // CHECK: define hidden void @_ZN5Test11fEv
15 void HIDDEN f() { }
16
17}
18
19namespace Test2 {
20 struct HIDDEN A {
21 void f();
22 };
23
24 // A::f is a member function of a hidden class.
25 // CHECK: define hidden void @_ZN5Test21A1fEv
26 void A::f() { }
27}
28
29namespace Test3 {
30 struct HIDDEN A {
31 struct B {
32 void f();
33 };
34 };
35
36 // B is a nested class where its parent class is hidden.
37 // CHECK: define hidden void @_ZN5Test31A1B1fEv
38 void A::B::f() { }
39}
40
41namespace Test4 HIDDEN {
42 int VariableInHiddenNamespace = 10;
43
44 // Test4::g is in a hidden namespace.
45 // CHECK: define hidden void @_ZN5Test41gEv
46 void g() { }
47
48 struct DEFAULT A {
49 void f();
50 };
51
52 // A has default visibility.
53 // CHECK: define void @_ZN5Test41A1fEv
54 void A::f() { }
55}
56
57namespace Test5 {
58
59 namespace NS HIDDEN {
60 // f is in NS which is hidden.
61 // CHECK: define hidden void @_ZN5Test52NS1fEv()
62 void f() { }
63 }
64
65 namespace NS {
66 // g is in NS, but this NS decl is not hidden.
67 // CHECK: define void @_ZN5Test52NS1gEv
68 void g() { }
69 }
70}
Douglas Gregorc66bcfd2010-06-14 23:41:45 +000071
72// <rdar://problem/8091955>
73namespace Test6 {
74 struct HIDDEN foo {
75 foo() { }
76 void bonk();
77 virtual void bar() = 0;
78
79 virtual void zonk() {}
80 };
81
82 struct barc : public foo {
83 barc();
84 virtual void bar();
85 };
86
87 barc::barc() {}
88}
John McCall1fb0caa2010-10-22 21:05:15 +000089
90namespace Test7 {
91 class HIDDEN A {};
92 A a; // top of file
93
94 template <A&> struct Aref {
95 static void foo() {}
96 };
97
98 class B : public A {};
99 B b; // top of file
100
101 // CHECK: define linkonce_odr hidden void @_ZN5Test74ArefILZNS_1aEEE3fooEv()
102 void test() {
103 Aref<a>::foo();
104 }
105}
106
107namespace Test8 {
108 void foo();
109 void bar() {}
110 // CHECK-HIDDEN: define hidden void @_ZN5Test83barEv()
111 // CHECK-HIDDEN: declare void @_ZN5Test83fooEv()
112
113 void test() {
114 foo();
115 bar();
116 }
117}