mangle.cpp revision e170ba7846bc4cae4b376b52eb4448645c141e59
1// RUN: clang-cc -emit-llvm %s -o - -triple=x86_64-apple-darwin9 | FileCheck %s
2
3struct X { };
4struct 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
13bool operator+(const Y&, X* (&xs)[100]) { return false; }
14
15// CHECK: define void @_Z1f1s
16typedef struct { int a; } s;
17void f(s) { }
18
19// CHECK: define void @_Z1f1e
20typedef enum { foo } e;
21void f(e) { }
22
23// CHECK: define void @_Z1f1u
24typedef union { int a; } u;
25void f(u) { }
26
27// CHECK: define void @_Z1f1x
28typedef struct { int a; } x,y;
29void f(y) { }
30
31// CHECK: define void @_Z1fv
32void f() { }
33
34// CHECK: define void @_ZN1N1fEv
35namespace N { void f() { } }
36
37// CHECK: define void @_ZN1N1N1fEv
38namespace N { namespace N { void f() { } } }
39
40// CHECK: define void @unmangled_function
41extern "C" { namespace N { void unmangled_function() { } } }
42
43extern "C" { namespace N { int unmangled_variable = 10; } }
44
45namespace N { int i; }
46
47namespace N { int f(int, int) { static int b; return b; } }
48
49namespace N { int h(); void g() { static int a = h(); } }
50
51// CHECK: define void @_Z1fno
52void f(__int128_t, __uint128_t) { }
53
54template <typename T> struct S1 {};
55
56// CHECK: define void @_Z1f2S1IiE
57void f(S1<int>) {}
58
59// CHECK: define void @_Z1f2S1IdE
60void f(S1<double>) {}
61
62template <int N> struct S2 {};
63// CHECK: define void @_Z1f2S2ILi100EE
64void f(S2<100>) {}
65
66// CHECK: define void @_Z1f2S2ILin100EE
67void f(S2<-100>) {}
68
69template <bool B> struct S3 {};
70
71// CHECK: define void @_Z1f2S3ILb1EE
72void f(S3<true>) {}
73
74// CHECK: define void @_Z1f2S3ILb0EE
75void f(S3<false>) {}
76
77// CHECK: define void @_Z2f22S3ILb1EE
78void f2(S3<100>) {}
79
80struct S;
81
82// CHECK: define void @_Z1fM1SKFvvE
83void f(void (S::*)() const) {}
84
85// CHECK: define void @_Z1fM1SFvvE
86void f(void (S::*)()) {}
87
88// CHECK: define void @_Z1fi
89void f(const int) { }
90
91template<typename T, typename U> void ft1(U u, T t) { }
92
93template<typename T> void ft2(T t, void (*)(T), void (*)(T)) { }
94
95template<typename T, typename U = S1<T> > struct S4 { };
96template<typename T> void ft3(S4<T>*) {  }
97
98namespace NS {
99  template<typename T> void ft1(T) { }
100}
101
102void 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
117template<int I> struct S5 { };
118
119template<int I> void ft4(S5<I>) { }
120void g2() {
121  // CHECK: @_Z3ft4ILi10EEv2S5IXT_EE
122  ft4(S5<10>());
123
124  // CHECK: @_Z3ft4ILi20EEv2S5IXT_EE
125  ft4(S5<20>());
126}
127
128extern "C++" {
129  // CHECK: @_Z1hv
130 void h() { }
131}
132
133// PR5019
134extern "C" { struct a { int b; }; }
135
136// CHECK: @_Z1fP1a
137int f(struct a *x) {
138    return x->b;
139}
140
141// PR5017
142extern "C" {
143struct Debug {
144 const Debug& operator<< (unsigned a) const { }
145};
146Debug dbg;
147// CHECK: @_ZNK5DebuglsEj
148int main(void) {  dbg << 32 ;}
149}
150
151template<typename T> struct S6 {
152  typedef int B;
153};
154
155template<typename T> void ft5(typename S6<T>::B) { }
156// CHECK: @_Z3ft5IiEvN2S6IT_E1BE
157template void ft5<int>(int);
158
159template<typename T> class A {};
160
161namespace NS {
162template<typename T> bool operator==(const A<T>&, const A<T>&) { return true; }
163}
164
165// CHECK: @_ZN2NSeqIcEEbRK1AIT_ES5_
166template bool NS::operator==(const ::A<char>&, const ::A<char>&);
167
168namespace std {
169template<typename T> bool operator==(const A<T>&, const A<T>&) { return true; }
170}
171
172// CHECK: @_ZSteqIcEbRK1AIT_ES4_
173template bool std::operator==(const ::A<char>&, const ::A<char>&);
174
175struct S {
176  typedef int U;
177};
178
179template <typename T> typename T::U ft6(const T&) { return 0; }
180
181// CHECK: @_Z3ft6I1SENT_1UERKS1_
182template int ft6<S>(const S&);
183
184template<typename> struct __is_scalar {
185  enum { __value = 1 };
186};
187
188template<bool, typename> struct __enable_if { };
189
190template<typename T> struct __enable_if<true, T> {
191  typedef T __type;
192};
193
194// PR5063
195template<typename T> typename __enable_if<__is_scalar<T>::__value, void>::__type ft7() { }
196
197// CHECK: @_Z3ft7IiEN11__enable_ifIXsr11__is_scalarIT_E7__valueEvE6__typeEv
198template void ft7<int>();
199// CHECK: @_Z3ft7IPvEN11__enable_ifIXsr11__is_scalarIT_E7__valueEvE6__typeEv
200template void ft7<void*>();
201
202// PR5144
203extern "C" {
204void extern_f(void);
205};
206
207// CHECK: @extern_f
208void extern_f(void) { }
209
210struct S7 {
211  S7();
212
213  struct S { S(); };
214  struct {
215    S s;
216  } a;
217};
218
219// PR5139
220// CHECK: @_ZN2S7C1Ev
221// CHECK: @_ZN2S7C2Ev
222// CHECK: @"_ZN2S73$_0C1Ev"
223S7::S7() {}
224
225// PR5063
226template<typename T> typename __enable_if<(__is_scalar<T>::__value), void>::__type ft8() { }
227// CHECK: @_Z3ft8IiEN11__enable_ifIXsr11__is_scalarIT_E7__valueEvE6__typeEv
228template void ft8<int>();
229// CHECK: @_Z3ft8IPvEN11__enable_ifIXsr11__is_scalarIT_E7__valueEvE6__typeEv
230template void ft8<void*>();
231
232namespace Expressions {
233// Unary operators.
234
235// CHECK: define void @_ZN11Expressions2f1ILi1EEEvPAplngT_Li2E_i
236template <int i> void f1(int (*)[(-i) + 2]) { };
237template void f1<1>(int (*)[1]);
238
239// CHECK: define void @_ZN11Expressions2f2ILi1EEEvPApsT__i
240template <int i> void f2(int (*)[+i]) { };
241template void f2<1>(int (*)[1]);
242
243// Binary operators.
244
245// CHECK: define void @_ZN11Expressions2f3ILi1EEEvPAplT_T__i
246template <int i> void f3(int (*)[i+i]) { };
247template void f3<1>(int (*)[2]);
248
249// CHECK: define void @_ZN11Expressions2f4ILi1EEEvPAplplLi2ET_T__i
250template <int i> void f4(int (*)[2 + i+i]) { };
251template void f4<1>(int (*)[4]);
252
253// The ternary operator.
254// CHECK: define void @_ZN11Expressions2f4ILb1EEEvPAquT_Li1ELi2E_i
255template <bool b> void f4(int (*)[b ? 1 : 2]) { };
256template void f4<true>(int (*)[1]);
257
258}
259