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

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.

rdar://154969620
This commit is contained in:
Gabor Horvath
2025-07-31 13:07:31 +01:00
parent a47d39215d
commit 087793394c
4 changed files with 46 additions and 5 deletions

View File

@@ -2176,11 +2176,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,