]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CodeGenCXX/mangle.cpp
Update clang to r89205.
[FreeBSD/FreeBSD.git] / test / CodeGenCXX / mangle.cpp
1 // RUN: clang-cc -emit-llvm %s -o - -triple=x86_64-apple-darwin9 | FileCheck %s
2
3 struct X { };
4 struct Y { };
5
6 // CHECK: @unmangled_variable = global
7 // CHECK: @_ZN1N1iE = global
8 // CHECK: @_ZZN1N1fEiiE1b = internal global
9 // CHECK: @_ZZN1N1gEvE1a = internal global
10 // CHECK: @_ZGVZN1N1gEvE1a = internal global
11
12 // CHECK: define zeroext i1 @_ZplRK1YRA100_P1X
13 bool operator+(const Y&, X* (&xs)[100]) { return false; }
14
15 // CHECK: define void @_Z1f1s
16 typedef struct { int a; } s;
17 void f(s) { }
18
19 // CHECK: define void @_Z1f1e
20 typedef enum { foo } e;
21 void f(e) { }
22
23 // CHECK: define void @_Z1f1u
24 typedef union { int a; } u;
25 void f(u) { }
26
27 // CHECK: define void @_Z1f1x
28 typedef struct { int a; } x,y;
29 void f(y) { }
30
31 // CHECK: define void @_Z1fv
32 void f() { }
33
34 // CHECK: define void @_ZN1N1fEv
35 namespace N { void f() { } }
36
37 // CHECK: define void @_ZN1N1N1fEv
38 namespace N { namespace N { void f() { } } }
39
40 // CHECK: define void @unmangled_function
41 extern "C" { namespace N { void unmangled_function() { } } }
42
43 extern "C" { namespace N { int unmangled_variable = 10; } }
44
45 namespace N { int i; }
46
47 namespace N { int f(int, int) { static int b; return b; } }
48
49 namespace N { int h(); void g() { static int a = h(); } }
50
51 // CHECK: define void @_Z1fno
52 void f(__int128_t, __uint128_t) { } 
53
54 template <typename T> struct S1 {};
55
56 // CHECK: define void @_Z1f2S1IiE
57 void f(S1<int>) {}
58
59 // CHECK: define void @_Z1f2S1IdE
60 void f(S1<double>) {}
61
62 template <int N> struct S2 {};
63 // CHECK: define void @_Z1f2S2ILi100EE
64 void f(S2<100>) {}
65
66 // CHECK: define void @_Z1f2S2ILin100EE
67 void f(S2<-100>) {}
68
69 template <bool B> struct S3 {};
70
71 // CHECK: define void @_Z1f2S3ILb1EE
72 void f(S3<true>) {}
73
74 // CHECK: define void @_Z1f2S3ILb0EE
75 void f(S3<false>) {}
76
77 // CHECK: define void @_Z2f22S3ILb1EE
78 void f2(S3<100>) {}
79
80 struct S;
81
82 // CHECK: define void @_Z1fM1SKFvvE
83 void f(void (S::*)() const) {}
84
85 // CHECK: define void @_Z1fM1SFvvE
86 void f(void (S::*)()) {}
87
88 // CHECK: define void @_Z1fi
89 void f(const int) { }
90
91 template<typename T, typename U> void ft1(U u, T t) { }
92
93 template<typename T> void ft2(T t, void (*)(T), void (*)(T)) { }
94
95 template<typename T, typename U = S1<T> > struct S4 { };
96 template<typename T> void ft3(S4<T>*) {  }
97
98 namespace NS {
99   template<typename T> void ft1(T) { }
100 }
101
102 void g1() {
103   // CHECK: @_Z3ft1IidEvT0_T_
104   ft1<int, double>(1, 0);
105   
106   // CHECK: @_Z3ft2IcEvT_PFvS0_ES2_
107   ft2<char>(1, 0, 0);
108   
109   // CHECK: @_Z3ft3IiEvP2S4IT_2S1IS1_EE
110   ft3<int>(0);
111   
112   // CHECK: @_ZN2NS3ft1IiEEvT_
113   NS::ft1<int>(1);
114 }
115
116 // Expressions
117 template<int I> struct S5 { };
118
119 template<int I> void ft4(S5<I>) { }
120 void g2() {
121   // CHECK: @_Z3ft4ILi10EEv2S5IXT_EE
122   ft4(S5<10>());
123   
124   // CHECK: @_Z3ft4ILi20EEv2S5IXT_EE
125   ft4(S5<20>());
126 }
127
128 extern "C++" {
129   // CHECK: @_Z1hv
130  void h() { } 
131 }
132
133 // PR5019
134 extern "C" { struct a { int b; }; }
135
136 // CHECK: @_Z1fP1a
137 int f(struct a *x) {
138     return x->b;
139 }
140
141 // PR5017
142 extern "C" {
143 struct Debug {
144  const Debug& operator<< (unsigned a) const { }
145 };
146 Debug dbg;
147 // CHECK: @_ZNK5DebuglsEj
148 int main(void) {  dbg << 32 ;}
149 }
150
151 template<typename T> struct S6 {
152   typedef int B;
153 };
154
155 template<typename T> void ft5(typename S6<T>::B) { }
156 // CHECK: @_Z3ft5IiEvN2S6IT_E1BE
157 template void ft5<int>(int);
158
159 template<typename T> class A {};
160
161 namespace NS {
162 template<typename T> bool operator==(const A<T>&, const A<T>&) { return true; }
163 }
164
165 // CHECK: @_ZN2NSeqIcEEbRK1AIT_ES5_
166 template bool NS::operator==(const ::A<char>&, const ::A<char>&);
167
168 namespace std {
169 template<typename T> bool operator==(const A<T>&, const A<T>&) { return true; }
170 }
171
172 // CHECK: @_ZSteqIcEbRK1AIT_ES4_
173 template bool std::operator==(const ::A<char>&, const ::A<char>&);
174
175 struct S {
176   typedef int U;
177 };
178
179 template <typename T> typename T::U ft6(const T&) { return 0; }
180
181 // CHECK: @_Z3ft6I1SENT_1UERKS1_
182 template int ft6<S>(const S&);
183
184 template<typename> struct __is_scalar {
185   enum { __value = 1 };
186 };
187
188 template<bool, typename> struct __enable_if { };
189
190 template<typename T> struct __enable_if<true, T> {
191   typedef T __type;
192 };
193
194 // PR5063
195 template<typename T> typename __enable_if<__is_scalar<T>::__value, void>::__type ft7() { }
196
197 // CHECK: @_Z3ft7IiEN11__enable_ifIXsr11__is_scalarIT_E7__valueEvE6__typeEv
198 template void ft7<int>();
199 // CHECK: @_Z3ft7IPvEN11__enable_ifIXsr11__is_scalarIT_E7__valueEvE6__typeEv
200 template void ft7<void*>();
201
202 // PR5144
203 extern "C" {
204 void extern_f(void);
205 };
206
207 // CHECK: @extern_f
208 void extern_f(void) { }
209
210 struct S7 {
211   struct S { S(); };
212   
213   struct {
214     S s;
215   } a;
216 };
217
218 // PR5139
219 // CHECK: @_ZN2S7C1Ev
220 // CHECK: @_ZN2S7C2Ev
221 // CHECK: @"_ZN2S73$_0C1Ev"
222 S7::S7() {}
223
224 // PR5063
225 template<typename T> typename __enable_if<(__is_scalar<T>::__value), void>::__type ft8() { }
226 // CHECK: @_Z3ft8IiEN11__enable_ifIXsr11__is_scalarIT_E7__valueEvE6__typeEv
227 template void ft8<int>();
228 // CHECK: @_Z3ft8IPvEN11__enable_ifIXsr11__is_scalarIT_E7__valueEvE6__typeEv
229 template void ft8<void*>();