File: mangle-ms-auto-return.cpp

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,235,796 kB
  • sloc: cpp: 7,617,614; ansic: 1,433,901; asm: 1,058,726; python: 252,096; f90: 94,671; objc: 70,753; lisp: 42,813; pascal: 18,401; sh: 10,032; ml: 5,111; perl: 4,720; awk: 3,523; makefile: 3,401; javascript: 2,272; xml: 892; fortran: 770
file content (397 lines) | stat: -rw-r--r-- 10,834 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
// RUN: %clang_cc1 -std=c++17 -fms-compatibility-version=19.20 -emit-llvm %s -o - -fms-extensions -fdelayed-template-parsing -triple=x86_64-pc-windows-msvc | FileCheck %s

struct StructA {};

template<class T>
auto AutoT() { return T(); }

template<class T>
const auto AutoConstT() { return T(); }

template<class T>
volatile auto AutoVolatileT() { return T(); }

template<class T>
const volatile auto AutoConstVolatileT() { return T(); }

// The qualifiers of the return type should always be emitted even for void types.
// Void types usually have their qualifers stripped in the mangled name for MSVC ABI.
void test_template_auto_void() {
  AutoT<void>();
  // CHECK: call {{.*}} @"??$AutoT@X@@YA?A_PXZ"

  AutoT<const void>();
  // CHECK: call {{.*}} @"??$AutoT@$$CBX@@YA?A_PXZ"

  AutoT<volatile void>();
  // CHECK: call {{.*}} @"??$AutoT@$$CCX@@YA?A_PXZ"

  AutoT<const volatile void>();
  // CHECK: call {{.*}} @"??$AutoT@$$CDX@@YA?A_PXZ"

  AutoConstT<void>();
  // CHECK: call {{.*}} @"??$AutoConstT@X@@YA?B_PXZ"

  AutoVolatileT<void>();
  // CHECK: call {{.*}} @"??$AutoVolatileT@X@@YA?C_PXZ"

  AutoConstVolatileT<void>();
  // CHECK: call {{.*}} @"??$AutoConstVolatileT@X@@YA?D_PXZ"
}

void test_template_auto_int() {
  AutoT<int>();
  // CHECK: call {{.*}} @"??$AutoT@H@@YA?A_PXZ"

  AutoT<const int>();
  // CHECK: call {{.*}} @"??$AutoT@$$CBH@@YA?A_PXZ"

  AutoT<volatile int>();
  // CHECK: call {{.*}} @"??$AutoT@$$CCH@@YA?A_PXZ"

  AutoT<const volatile int>();
  // CHECK: call {{.*}} @"??$AutoT@$$CDH@@YA?A_PXZ"

  AutoConstT<int>();
  // CHECK: call {{.*}} @"??$AutoConstT@H@@YA?B_PXZ"

  AutoVolatileT<int>();
  // CHECK: call {{.*}} @"??$AutoVolatileT@H@@YA?C_PXZ"

  AutoConstVolatileT<int>();
  // CHECK: call {{.*}} @"??$AutoConstVolatileT@H@@YA?D_PXZ"
}

void test_template_auto_struct() {
  AutoT<StructA>();
  // CHECK: call {{.*}} @"??$AutoT@UStructA@@@@YA?A_PXZ"

  AutoT<const StructA>();
  // CHECK: call {{.*}} @"??$AutoT@$$CBUStructA@@@@YA?A_PXZ"

  AutoConstT<StructA>();
  // CHECK: call {{.*}} @"??$AutoConstT@UStructA@@@@YA?B_PXZ"

  AutoVolatileT<StructA>();
  // CHECK: call {{.*}} @"??$AutoVolatileT@UStructA@@@@YA?C_PXZ"

  AutoConstVolatileT<StructA>();
  // CHECK: call {{.*}} @"??$AutoConstVolatileT@UStructA@@@@YA?D_PXZ"
}

void test_template_auto_ptr() {
  AutoT<int*>();
  // CHECK: call {{.*}} @"??$AutoT@PEAH@@YA?A_PXZ"

  AutoT<const int*>();
  // CHECK: call {{.*}} @"??$AutoT@PEBH@@YA?A_PXZ"

  AutoT<const int* const>();
  // CHECK: call {{.*}} @"??$AutoT@QEBH@@YA?A_PXZ"

  AutoConstT<int*>();
  // CHECK: call {{.*}} @"??$AutoConstT@PEAH@@YA?B_PXZ"

  AutoVolatileT<int*>();
  // CHECK: call {{.*}} @"??$AutoVolatileT@PEAH@@YA?C_PXZ"

  AutoConstVolatileT<int*>();
  // CHECK: call {{.*}} @"??$AutoConstVolatileT@PEAH@@YA?D_PXZ"
}

template<class T>
auto* PtrAutoT() { return T(); }

template<class T>
const auto* PtrAutoConstT() { return T(); }

template<class T>
volatile auto* PtrAutoVolatileT() { return T(); }

template<class T>
const volatile auto* PtrAutoConstVolatileT() { return T(); }

void test_template_ptr_auto() {
  PtrAutoT<int*>();
  // CHECK: call {{.*}} @"??$PtrAutoT@PEAH@@YAPEA_PXZ"

  PtrAutoT<const int*>();
  // CHECK: call {{.*}} @"??$PtrAutoT@PEBH@@YAPEA_PXZ"

  PtrAutoT<const int* const>();
  // CHECK: call {{.*}} @"??$PtrAutoT@QEBH@@YAPEA_PXZ"

  PtrAutoConstT<int*>();
  // CHECK: call {{.*}} @"??$PtrAutoConstT@PEAH@@YAPEB_PXZ"

  PtrAutoVolatileT<int*>();
  // CHECK: call {{.*}} @"??$PtrAutoVolatileT@PEAH@@YAPEC_PXZ"

  PtrAutoConstVolatileT<int*>();
  // CHECK: call {{.*}} @"??$PtrAutoConstVolatileT@PEAH@@YAPED_PXZ"
}

int func_int();
const int func_constint();
void func_void();
int* func_intptr();

template<class T, T v>
auto (*FuncPtrAutoT())() { return v; }

void test_template_func_ptr_auto() {
  FuncPtrAutoT<int (*)(), &func_int>();
  // CHECK: call {{.*}} @"??$FuncPtrAutoT@P6AHXZ$1?func_int@@YAHXZ@@YAP6A?A_PXZXZ"

  FuncPtrAutoT<const int (*)(), &func_constint>();
  // CHECK: call {{.*}} @"??$FuncPtrAutoT@P6A?BHXZ$1?func_constint@@YA?BHXZ@@YAP6A?A_PXZXZ"

  FuncPtrAutoT<void (*)(), &func_void>();
  // CHECK: call {{.*}} @"??$FuncPtrAutoT@P6AXXZ$1?func_void@@YAXXZ@@YAP6A?A_PXZXZ"

  FuncPtrAutoT<int * (*)(), &func_intptr>();
  // CHECK: call {{.*}} @"??$FuncPtrAutoT@P6APEAHXZ$1?func_intptr@@YAPEAHXZ@@YAP6A?A_PXZXZ"
}

template<class T>
auto& RefAutoT(T& x) { return x; }

template<class T>
const auto& ConstRefAutoT(T& x) { return x; }

template<class T>
auto&& RRefAutoT(T& x) { return static_cast<int&&>(x); }

void test_template_ref_auto() {
  int x;

  RefAutoT(x);
  // CHECK: call {{.*}} @"??$RefAutoT@H@@YAAEA_PAEAH@Z"

  ConstRefAutoT(x);
  // CHECK: call {{.*}} @"??$ConstRefAutoT@H@@YAAEB_PAEAH@Z"

  RRefAutoT(x);
  // CHECK: call {{.*}} @"??$RRefAutoT@H@@YA$$QEA_PAEAH@Z"
}

template<class T>
decltype(auto) DecltypeAutoT() { return T(); }

template<class T>
decltype(auto) DecltypeAutoT2(T& x) { return static_cast<T&&>(x); }

void test_template_decltypeauto() {
  DecltypeAutoT<void>();
  // CHECK: call {{.*}} @"??$DecltypeAutoT@X@@YA?A_TXZ"

  DecltypeAutoT<const void>();
  // CHECK: call {{.*}} @"??$DecltypeAutoT@$$CBX@@YA?A_TXZ"

  DecltypeAutoT<volatile void>();
  // CHECK: call {{.*}} @"??$DecltypeAutoT@$$CCX@@YA?A_TXZ"

  DecltypeAutoT<const volatile void>();
  // CHECK: call {{.*}} @"??$DecltypeAutoT@$$CDX@@YA?A_TXZ"

  DecltypeAutoT<int>();
  // CHECK: call {{.*}} @"??$DecltypeAutoT@H@@YA?A_TXZ"

  DecltypeAutoT<const int>();
  // CHECK: call {{.*}} @"??$DecltypeAutoT@$$CBH@@YA?A_TXZ"

  DecltypeAutoT<volatile int>();
  // CHECK: call {{.*}} @"??$DecltypeAutoT@$$CCH@@YA?A_TXZ"

  DecltypeAutoT<const volatile int>();
  // CHECK: call {{.*}} @"??$DecltypeAutoT@$$CDH@@YA?A_TXZ"

  int x;

  DecltypeAutoT2(x);
  // CHECK: call {{.*}} @"??$DecltypeAutoT2@H@@YA?A_TAEAH@Z"
}

// Still want to use clang's custom mangling for lambdas to keep backwards compatibility until
// MSVC lambda name mangling has been deciphered.
void test_lambda() {
  int i = 0;

  auto lambdaIntRetAuto = []() { return 0; };
  lambdaIntRetAuto();
  // CHECK: call {{.*}} @"??R<lambda_1>@?0??test_lambda@@YAXXZ@QEBA?A?<auto>@@XZ"

  auto lambdaIntRet = []() -> int { return 0; };
  lambdaIntRet();
  // CHECK: call {{.*}} @"??R<lambda_2>@?0??test_lambda@@YAXXZ@QEBA@XZ"

  auto lambdaGenericIntIntRetAuto = [](auto a) { return a; };
  lambdaGenericIntIntRetAuto(0);
  // CHECK: call {{.*}} @"??$?RH@<lambda_0>@?0??test_lambda@@YAXXZ@QEBA?A?<auto>@@H@Z"

  auto lambdaRetTrailingAuto = []() -> auto { return 0; };
  lambdaRetTrailingAuto();
  // CHECK: call {{.*}} @"??R<lambda_3>@?0??test_lambda@@YAXXZ@QEBA?A?<auto>@@XZ"

  auto lambdaRetTrailingDecltypeAuto = []() -> decltype(auto) { return 0; };
  lambdaRetTrailingDecltypeAuto();
  // CHECK: call {{.*}} @"??R<lambda_4>@?0??test_lambda@@YAXXZ@QEBA?A?<decltype-auto>@@XZ"

  auto lambdaRetTrailingRefCollapse = [](int x) -> auto&& { return x; };
  lambdaRetTrailingRefCollapse(i);
  // CHECK: call {{.*}} @"??R<lambda_5>@?0??test_lambda@@YAXXZ@QEBA?A?<auto>@@H@Z"
}

auto TestTrailingInt() -> int {
  return 0;
}

auto TestTrailingConstVolatileVoid() -> const volatile void {
}

auto TestTrailingStructA() -> StructA {
  return StructA{};
}

void test_trailing_return() {
  TestTrailingInt();
  // CHECK: call {{.*}} @"?TestTrailingInt@@YAHXZ"

  TestTrailingConstVolatileVoid();
  // CHECK: call {{.*}} @"?TestTrailingConstVolatileVoid@@YAXXZ"

  TestTrailingStructA();
  // CHECK: call {{.*}} @"?TestTrailingStructA@@YA?AUStructA@@XZ"
}

auto TestNonTemplateAutoInt() {
  return 0;
}

auto TestNonTemplateAutoVoid() {
  return;
}

auto TestNonTemplateAutoStructA() {
  return StructA{};
}

const auto TestNonTemplateConstAutoInt() {
  return 0;
}

const auto TestNonTemplateConstAutoVoid() {
  return;
}

const auto TestNonTemplateConstAutoStructA() {
  return StructA{};
}

void test_nontemplate_auto() {
  TestNonTemplateAutoInt();
  // CHECK: call {{.*}} @"?TestNonTemplateAutoInt@@YA@XZ"

  TestNonTemplateAutoVoid();
  // CHECK: call {{.*}} @"?TestNonTemplateAutoVoid@@YA@XZ"

  TestNonTemplateAutoStructA();
  // CHECK: call {{.*}} @"?TestNonTemplateAutoStructA@@YA@XZ"

  TestNonTemplateConstAutoInt();
  // CHECK: call {{.*}} @"?TestNonTemplateConstAutoInt@@YA@XZ"

  TestNonTemplateConstAutoVoid();
  // CHECK: call {{.*}} @"?TestNonTemplateConstAutoVoid@@YA@XZ"

  TestNonTemplateConstAutoStructA();
  // CHECK: call {{.*}} @"?TestNonTemplateConstAutoStructA@@YA@XZ"
}

decltype(auto) TestNonTemplateDecltypeAutoInt() {
    return 0;
}

decltype(auto) TestNonTemplateDecltypeAutoVoid() {
    return;
}

decltype(auto) TestNonTemplateDecltypeAutoStructA() {
    return StructA{};
}

void test_nontemplate_decltypeauto() {
  TestNonTemplateDecltypeAutoInt();
  // CHECK: call {{.*}} @"?TestNonTemplateDecltypeAutoInt@@YA@XZ"

  TestNonTemplateDecltypeAutoVoid();
  // CHECK: call {{.*}} @"?TestNonTemplateDecltypeAutoVoid@@YA@XZ"

  TestNonTemplateDecltypeAutoStructA();
  // CHECK: call {{.*}} @"?TestNonTemplateDecltypeAutoStructA@@YA@XZ"
}

struct StructB {
  int x;
};

template<class T>
auto StructB::* AutoMemberDataPtrT(T x) { return x; }

template<class T>
const auto StructB::* AutoConstMemberDataPtrT(T x) { return x; }

void test_template_auto_member_data_ptr() {
  AutoMemberDataPtrT(&StructB::x);
  // CHECK: call {{.*}} @"??$AutoMemberDataPtrT@PEQStructB@@H@@YAPEQStructB@@_PPEQ0@H@Z"

  AutoConstMemberDataPtrT(&StructB::x);
  // CHECK: call {{.*}} @"??$AutoConstMemberDataPtrT@PEQStructB@@H@@YAPERStructB@@_PPEQ0@H@Z"
}

struct StructC {
  void test() {}
};

struct StructD {
  const int test() { return 0; }
};

template<class T>
auto (StructC::*AutoMemberFuncPtrT(T x))() { return x; }

template<class T>
const auto (StructD::*AutoConstMemberFuncPtrT(T x))() { return x; }

void test_template_auto_member_func_ptr() {
  AutoMemberFuncPtrT(&StructC::test);
  // CHECK: call {{.*}} @"??$AutoMemberFuncPtrT@P8StructC@@EAAXXZ@@YAP8StructC@@EAA?A_PXZP80@EAAXXZ@Z"

  AutoConstMemberFuncPtrT(&StructD::test);
  // CHECK: call {{.*}} @"??$AutoConstMemberFuncPtrT@P8StructD@@EAA?BHXZ@@YAP8StructD@@EAA?B_PXZP80@EAA?BHXZ@Z"
}

template<class T>
auto * __attribute__((address_space(1))) * AutoPtrAddressSpaceT() {
  T * __attribute__((address_space(1))) * p = nullptr;
  return p;
}

void test_template_auto_address_space_ptr() {
  AutoPtrAddressSpaceT<int>();
  // CHECK: call {{.*}} @"??$AutoPtrAddressSpaceT@H@@YA?A?<auto>@@XZ"
}

template<class T>
auto&& AutoReferenceCollapseT(T& x) { return static_cast<T&>(x); }

auto&& AutoReferenceCollapse(int& x) { return static_cast<int&>(x); }

void test2() {
  int x = 1;
  auto&& rref0 = AutoReferenceCollapseT(x);
  // CHECK: call {{.*}} @"??$AutoReferenceCollapseT@H@@YA$$QEA_PAEAH@Z"

  auto&& rref1 = AutoReferenceCollapse(x);
  // CHECK: call {{.*}} @"?AutoReferenceCollapse@@YA@AEAH@Z"
}