[clang] [clang-cl] [AST] Fix MS 1920+ placeholder return type mangling for lambdas (PR #105999)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 25 11:41:30 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Max Winkler (MaxEW707)
<details>
<summary>Changes</summary>
Fixes https://github.com/llvm/llvm-project/pull/104722.
Missed handling `decltype(auto)` trailing return types for lambdas.
This was a mistake and regression on my part with my PR, https://github.com/llvm/llvm-project/pull/104722.
Added some missing unit tests to test for the various placeholder trailing return types in lambdas.
---
Full diff: https://github.com/llvm/llvm-project/pull/105999.diff
2 Files Affected:
- (modified) clang/lib/AST/MicrosoftMangle.cpp (+3-4)
- (modified) clang/test/CodeGenCXX/mangle-ms-auto-return.cpp (+14)
``````````diff
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index b539681984ef7c..018ab617a0ecee 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -2967,13 +2967,12 @@ void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T,
mangleType(ResultType, Range, QMM_Result);
} else if (IsInLambda) {
if (const auto *AT = ResultType->getContainedAutoType()) {
- assert(AT->getKeyword() == AutoTypeKeyword::Auto &&
- "should only need to mangle auto!");
- (void)AT;
+ assert(AT->getKeyword() != AutoTypeKeyword::GNUAutoType &&
+ "shouldn't need to mangle __auto_type!");
Out << '?';
mangleQualifiers(ResultType.getLocalQualifiers(), /*IsMember=*/false);
Out << '?';
- mangleSourceName("<auto>");
+ mangleSourceName(AT->isDecltypeAuto() ? "<decltype-auto>" : "<auto>");
Out << '@';
} else {
Out << '@';
diff --git a/clang/test/CodeGenCXX/mangle-ms-auto-return.cpp b/clang/test/CodeGenCXX/mangle-ms-auto-return.cpp
index 5b18dcc0820ee6..0cf59ac962a764 100644
--- a/clang/test/CodeGenCXX/mangle-ms-auto-return.cpp
+++ b/clang/test/CodeGenCXX/mangle-ms-auto-return.cpp
@@ -215,6 +215,8 @@ void test_template_decltypeauto() {
// 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 at QEBA?A?<auto>@@XZ"
@@ -226,6 +228,18 @@ void test_lambda() {
auto lambdaGenericIntIntRetAuto = [](auto a) { return a; };
lambdaGenericIntIntRetAuto(0);
// CHECK: call {{.*}} @"??$?RH@<lambda_0>@?0??test_lambda@@YAXXZ at QEBA?A?<auto>@@H at Z"
+
+ auto lambdaRetTrailingAuto = []() -> auto { return 0; };
+ lambdaRetTrailingAuto();
+ // CHECK: call {{.*}} @"??R<lambda_3>@?0??test_lambda@@YAXXZ at QEBA?A?<auto>@@XZ"
+
+ auto lambdaRetTrailingDecltypeAuto = []() -> decltype(auto) { return 0; };
+ lambdaRetTrailingDecltypeAuto();
+ // CHECK: call {{.*}} @"??R<lambda_4>@?0??test_lambda@@YAXXZ at QEBA?A?<decltype-auto>@@XZ"
+
+ auto lambdaRetTrailingRefCollapse = [](int x) -> auto&& { return x; };
+ lambdaRetTrailingRefCollapse(i);
+ // CHECK: call {{.*}} @"??R<lambda_5>@?0??test_lambda@@YAXXZ at QEBA?A?<auto>@@H at Z"
}
auto TestTrailingInt() -> int {
``````````
</details>
https://github.com/llvm/llvm-project/pull/105999
More information about the cfe-commits
mailing list