1 // RUN: %clang_cc1 -fms-extensions -fblocks -emit-llvm %s -o - -cxx-abi microsoft -triple=i386-pc-win32 | FileCheck %s
2 
3 // NOTE on the "CURRENT" prefix: some things are mangled incorrectly as of
4 // writing. If you find a CURRENT-test that fails with your patch, please test
5 // if your patch has actually fixed a problem in the mangler and replace the
6 // corresponding CORRECT line with a CHECK.
7 // RUN: %clang_cc1 -fms-extensions -fblocks -emit-llvm %s -o - -cxx-abi microsoft -triple=i386-pc-win32 | FileCheck -check-prefix CURRENT %s
8 
9 void f1(const char* a, const char* b) {}
10 // CHECK: "\01?f1@@YAXPBD0@Z"
11 
12 void f2(const char* a, char* b) {}
13 // CHECK: "\01?f2@@YAXPBDPAD@Z"
14 
15 void f3(int a, const char* b, const char* c) {}
16 // CHECK: "\01?f3@@YAXHPBD0@Z"
17 
18 const char *f4(const char* a, const char* b) { return 0; }
19 // CHECK: "\01?f4@@YAPBDPBD0@Z"
20 
21 void f5(char const* a, unsigned int b, char c, void const* d, char const* e, unsigned int f) {}
22 // CHECK: "\01?f5@@YAXPBDIDPBX0I@Z"
23 
24 void f6(bool a, bool b) {}
25 // CHECK: "\01?f6@@YAX_N0@Z"
26 
27 void f7(int a, int* b, int c, int* d, bool e, bool f, bool* g) {}
28 // CHECK: "\01?f7@@YAXHPAHH0_N1PA_N@Z"
29 
30 // FIXME: tests for more than 10 types?
31 
32 struct S {
33   void mbb(bool a, bool b) {}
34 };
35 
36 void g1(struct S a) {}
37 // CHECK: "\01?g1@@YAXUS@@@Z"
38 
39 void g2(struct S a, struct S b) {}
40 // CHECK: "\01?g2@@YAXUS@@0@Z"
41 
42 void g3(struct S a, struct S b, struct S* c, struct S* d) {}
43 // CHECK: "\01?g3@@YAXUS@@0PAU1@1@Z"
44 
45 void g4(const char* a, struct S* b, const char* c, struct S* d) {
46 // CHECK: "\01?g4@@YAXPBDPAUS@@01@Z"
47   b->mbb(false, false);
48 // CHECK: "\01?mbb@S@@QAEX_N0@Z"
49 }
50 
51 // Make sure that different aliases of built-in types end up mangled as the
52 // built-ins.
53 typedef unsigned int uintptr_t;
54 typedef unsigned int size_t;
55 void *h(size_t a, uintptr_t b) { return 0; }
56 // CHECK: "\01?h@@YAPAXII@Z"
57 
58 // Function pointers might be mangled in a complex way.
59 typedef void (*VoidFunc)();
60 typedef int* (*PInt3Func)(int* a, int* b);
61 
62 void h1(const char* a, const char* b, VoidFunc c, VoidFunc d) {}
63 // CHECK: "\01?h1@@YAXPBD0P6AXXZ1@Z"
64 
65 void h2(void (*f_ptr)(void *), void *arg) {}
66 // CHECK: "\01?h2@@YAXP6AXPAX@Z0@Z"
67 
68 PInt3Func h3(PInt3Func x, PInt3Func y, int* z) { return 0; }
69 // CHECK: "\01?h3@@YAP6APAHPAH0@ZP6APAH00@Z10@Z"
70 
71 namespace PR13207 {
72 class A {};
73 class B {};
74 class C {};
75 
76 template<class X>
77 class F {};
78 template<class X>
79 class I {};
80 template<class X, class Y>
81 class J {};
82 template<class X, class Y, class Z>
83 class K {};
84 
85 class L {
86  public:
87   void foo(I<A> x) {}
88 };
89 // CHECK: "\01?foo@L@PR13207@@QAEXV?$I@VA@PR13207@@@2@@Z"
90 
91 void call_l_foo(L* l) { l->foo(I<A>()); }
92 
93 void foo(I<A> x) {}
94 // CHECK: "\01?foo@PR13207@@YAXV?$I@VA@PR13207@@@1@@Z"
95 void foo2(I<A> x, I<A> y) { }
96 // CHECK "\01?foo2@PR13207@@YAXV?$I@VA@PR13207@@@1@0@Z"
97 void bar(J<A,B> x) {}
98 // CHECK: "\01?bar@PR13207@@YAXV?$J@VA@PR13207@@VB@2@@1@@Z"
99 void spam(K<A,B,C> x) {}
100 // CHECK: "\01?spam@PR13207@@YAXV?$K@VA@PR13207@@VB@2@VC@2@@1@@Z"
101 
102 // The following CURRENT line is here to improve the precision of the "scanning
103 // from here" reports of FileCheck.
104 // CURRENT: "\01?spam@PR13207@@YAXV?$K@VA@PR13207@@VB@2@VC@2@@1@@Z"
105 
106 // The tests below currently fail:
107 void baz(K<char, F<char>, I<char> >) {}
108 // CURRENT: "\01?baz@PR13207@@YAXV?$K@DV?$F@D@PR13207@@V?$I@D@1@@1@@Z"
109 // CORRECT: "\01?baz@PR13207@@YAXV?$K@DV?$F@D@PR13207@@V?$I@D@2@@1@@Z"
110 void qux(K<char, I<char>, I<char> >) {}
111 // CURRENT: "\01?qux@PR13207@@YAXV?$K@DV?$I@D@PR13207@@V?$I@D@1@@1@@Z"
112 // CORRECT: "\01?qux@PR13207@@YAXV?$K@DV?$I@D@PR13207@@V12@@1@@Z
113 
114 namespace NA {
115 class X {};
116 template<class T> class Y {};
117 void foo(Y<X> x) {}
118 // CHECK: "\01?foo@NA@PR13207@@YAXV?$Y@VX@NA@PR13207@@@12@@Z"
119 }
120 
121 namespace NB {
122 class X {};
123 template<class T> class Y {};
124 void foo(Y<NA::X> x) {}
125 // CHECK: "\01?foo@NB@PR13207@@YAXV?$Y@VX@NA@PR13207@@@12@@Z"
126 
127 void bar(NA::Y<X> x) {}
128 // CHECK: "\01?bar@NB@PR13207@@YAXV?$Y@VX@NB@PR13207@@@NA@2@@Z"
129 
130 void spam(NA::Y<NA::X> x) {}
131 // CHECK: "\01?spam@NB@PR13207@@YAXV?$Y@VX@NA@PR13207@@@NA@2@@Z"
132 
133 // The tests below currently fail:
134 void foobar(NA::Y<Y<X> > a, Y<Y<X> >) {}
135 // CURRENT: "\01?foobar@NB@PR13207@@YAXV?$Y@V?$Y@VX@NB@PR13207@@@NB@PR13207@@@NA@2@V?$Y@V?$Y@VX@NB@PR13207@@@NB@PR13207@@@12@@Z"
136 // CORRECT: "\01?foobar@NB@PR13207@@YAXV?$Y@V?$Y@VX@NB@PR13207@@@NB@PR13207@@@NA@2@V312@@Z"
137 
138 void foobarspam(Y<X> a, NA::Y<Y<X> > b, Y<Y<X> >) {}
139 // CURRENT: "\01?foobarspam@NB@PR13207@@YAXV?$Y@VX@NB@PR13207@@@12@V?$Y@V?$Y@VX@NB@PR13207@@@NB@PR13207@@@NA@2@V?$Y@V?$Y@VX@NB@PR13207@@@NB@PR13207@@@12@@Z"
140 // CORRECT: "\01?foobarspam@NB@PR13207@@YAXV?$Y@VX@NB@PR13207@@@12@V?$Y@V?$Y@VX@NB@PR13207@@@NB@PR13207@@@NA@2@V412@@Z"
141 
142 void foobarbaz(Y<X> a, NA::Y<Y<X> > b, Y<Y<X> >, Y<Y<X> > c) {}
143 // CURRENT: "\01?foobarbaz@NB@PR13207@@YAXV?$Y@VX@NB@PR13207@@@12@V?$Y@V?$Y@VX@NB@PR13207@@@NB@PR13207@@@NA@2@V?$Y@V?$Y@VX@NB@PR13207@@@NB@PR13207@@@12@2@Z"
144 // CORRECT: "\01?foobarbaz@NB@PR13207@@YAXV?$Y@VX@NB@PR13207@@@12@V?$Y@V?$Y@VX@NB@PR13207@@@NB@PR13207@@@NA@2@V412@2@Z"
145 
146 void foobarbazqux(Y<X> a, NA::Y<Y<X> > b, Y<Y<X> >, Y<Y<X> > c , NA::Y<Y<Y<X> > > d) {}
147 // CURRENT: "\01?foobarbazqux@NB@PR13207@@YAXV?$Y@VX@NB@PR13207@@@12@V?$Y@V?$Y@VX@NB@PR13207@@@NB@PR13207@@@NA@2@V?$Y@V?$Y@VX@NB@PR13207@@@NB@PR13207@@@12@2V?$Y@V?$Y@V?$Y@VX@NB@PR13207@@@NB@PR13207@@@NB@PR13207@@@32@@Z"
148 // CORRECT: "\01?foobarbazqux@NB@PR13207@@YAXV?$Y@VX@NB@PR13207@@@12@V?$Y@V?$Y@VX@NB@PR13207@@@NB@PR13207@@@NA@2@V412@2V?$Y@V?$Y@V?$Y@VX@NB@PR13207@@@NB@PR13207@@@NB@PR13207@@@52@@Z"
149 }
150 
151 namespace NC {
152 class X {};
153 template<class T> class Y {};
154 
155 void foo(Y<NB::X> x) {}
156 // CHECK: "\01?foo@NC@PR13207@@YAXV?$Y@VX@NB@PR13207@@@12@@Z"
157 
158 void foobar(NC::Y<NB::Y<NA::Y<NA::X> > > x) {}
159 // CHECK: "\01?foobar@NC@PR13207@@YAXV?$Y@V?$Y@V?$Y@VX@NA@PR13207@@@NA@PR13207@@@NB@PR13207@@@12@@Z"
160 }
161 }
162