Skip to content

Commit 2579b41

Browse files
authored
[clang-cl] [AST] Fix MS 1920+ placeholder return type mangling for lambdas (#105999)
Fixes #104722. Missed handling `decltype(auto)` trailing return types for lambdas. This was a mistake and regression on my part with my PR, #104722. Added some missing unit tests to test for the various placeholder trailing return types in lambdas.
1 parent dff3c96 commit 2579b41

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2967,13 +2967,12 @@ void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T,
29672967
mangleType(ResultType, Range, QMM_Result);
29682968
} else if (IsInLambda) {
29692969
if (const auto *AT = ResultType->getContainedAutoType()) {
2970-
assert(AT->getKeyword() == AutoTypeKeyword::Auto &&
2971-
"should only need to mangle auto!");
2972-
(void)AT;
2970+
assert(AT->getKeyword() != AutoTypeKeyword::GNUAutoType &&
2971+
"shouldn't need to mangle __auto_type!");
29732972
Out << '?';
29742973
mangleQualifiers(ResultType.getLocalQualifiers(), /*IsMember=*/false);
29752974
Out << '?';
2976-
mangleSourceName("<auto>");
2975+
mangleSourceName(AT->isDecltypeAuto() ? "<decltype-auto>" : "<auto>");
29772976
Out << '@';
29782977
} else {
29792978
Out << '@';

clang/test/CodeGenCXX/mangle-ms-auto-return.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ void test_template_decltypeauto() {
215215
// Still want to use clang's custom mangling for lambdas to keep backwards compatibility until
216216
// MSVC lambda name mangling has been deciphered.
217217
void test_lambda() {
218+
int i = 0;
219+
218220
auto lambdaIntRetAuto = []() { return 0; };
219221
lambdaIntRetAuto();
220222
// CHECK: call {{.*}} @"??R<lambda_1>@?0??test_lambda@@YAXXZ@QEBA?A?<auto>@@XZ"
@@ -226,6 +228,18 @@ void test_lambda() {
226228
auto lambdaGenericIntIntRetAuto = [](auto a) { return a; };
227229
lambdaGenericIntIntRetAuto(0);
228230
// CHECK: call {{.*}} @"??$?RH@<lambda_0>@?0??test_lambda@@YAXXZ@QEBA?A?<auto>@@H@Z"
231+
232+
auto lambdaRetTrailingAuto = []() -> auto { return 0; };
233+
lambdaRetTrailingAuto();
234+
// CHECK: call {{.*}} @"??R<lambda_3>@?0??test_lambda@@YAXXZ@QEBA?A?<auto>@@XZ"
235+
236+
auto lambdaRetTrailingDecltypeAuto = []() -> decltype(auto) { return 0; };
237+
lambdaRetTrailingDecltypeAuto();
238+
// CHECK: call {{.*}} @"??R<lambda_4>@?0??test_lambda@@YAXXZ@QEBA?A?<decltype-auto>@@XZ"
239+
240+
auto lambdaRetTrailingRefCollapse = [](int x) -> auto&& { return x; };
241+
lambdaRetTrailingRefCollapse(i);
242+
// CHECK: call {{.*}} @"??R<lambda_5>@?0??test_lambda@@YAXXZ@QEBA?A?<auto>@@H@Z"
229243
}
230244

231245
auto TestTrailingInt() -> int {

0 commit comments

Comments
 (0)