[6.2][cxx-interop] Fix import virtual methods with rvalue ref params

Explanation: We generate forwarding calls for virutal methods. These forwarding
calls had a type error when the original parameter had an rvalue reference type.
In those scenarios we need to insert a static cast to make the type checker happy.
Issues: rdar://154969620
Original PRs: #83453
Risk: Low, narrow fix.
Testing: Added a compiler test.
Reviewers: @egorzhdan
This commit is contained in:
Gábor Horváth
2025-08-01 22:25:05 +01:00
committed by Gabor Horvath
parent f15d600460
commit 448cdce50c
4 changed files with 46 additions and 5 deletions

View File

@@ -2168,11 +2168,18 @@ clang::CXXMethodDecl *SwiftDeclSynthesizer::synthesizeCXXForwardingMethod(
for (size_t i = 0; i < newMethod->getNumParams(); ++i) {
auto *param = newMethod->getParamDecl(i);
auto type = param->getType();
if (type->isReferenceType())
type = type->getPointeeType();
args.push_back(new (clangCtx) clang::DeclRefExpr(
clangCtx, param, false, type, clang::ExprValueKind::VK_LValue,
clang::SourceLocation()));
clang::Expr *argExpr = new (clangCtx) clang::DeclRefExpr(
clangCtx, param, false, type.getNonReferenceType(),
clang::ExprValueKind::VK_LValue, clang::SourceLocation());
if (type->isRValueReferenceType()) {
argExpr = clangSema
.BuildCXXNamedCast(
clang::SourceLocation(), clang::tok::kw_static_cast,
clangCtx.getTrivialTypeSourceInfo(type), argExpr,
clang::SourceRange(), clang::SourceRange())
.get();
}
args.push_back(argExpr);
}
auto memberCall = clangSema.BuildCallExpr(
nullptr, memberExpr, clang::SourceLocation(), args,