Skip to content

Commit 9dc3ab8

Browse files
committed
[cxx-interop] Do not crash for static operator()
This fixes an assertion failure: ``` Assertion failed: (isInstance() && "No 'this' for static methods!"), function getThisType, file DeclCXX.cpp, line 2636. ``` Clang changed it's handling of member call expressions in llvm/llvm-project@af47517 causing the assertion to fail when synthesizing a forwarding function declaration for `static operator()`. rdar://133257179
1 parent 39b8b3c commit 9dc3ab8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/ClangImporter/SwiftDeclSynthesizer.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,14 +2138,19 @@ clang::CXXMethodDecl *SwiftDeclSynthesizer::synthesizeCXXForwardingMethod(
21382138
thisExpr = conv.get();
21392139
}
21402140

2141+
auto memberExprTy =
2142+
(method->isStatic() && method->getOverloadedOperator() ==
2143+
clang::OverloadedOperatorKind::OO_Call)
2144+
? method->getType()
2145+
: clangCtx.BoundMemberTy;
21412146
auto memberExpr = clangSema.BuildMemberExpr(
21422147
thisExpr, /*isArrow=*/true, clang::SourceLocation(),
21432148
clang::NestedNameSpecifierLoc(), clang::SourceLocation(),
21442149
const_cast<clang::CXXMethodDecl *>(method),
21452150
clang::DeclAccessPair::make(const_cast<clang::CXXMethodDecl *>(method),
21462151
clang::AS_public),
21472152
/*HadMultipleCandidates=*/false, method->getNameInfo(),
2148-
clangCtx.BoundMemberTy, clang::VK_PRValue, clang::OK_Ordinary);
2153+
memberExprTy, clang::VK_PRValue, clang::OK_Ordinary);
21492154
llvm::SmallVector<clang::Expr *, 4> args;
21502155
for (size_t i = 0; i < newMethod->getNumParams(); ++i) {
21512156
auto *param = newMethod->getParamDecl(i);
@@ -2156,7 +2161,7 @@ clang::CXXMethodDecl *SwiftDeclSynthesizer::synthesizeCXXForwardingMethod(
21562161
clangCtx, param, false, type, clang::ExprValueKind::VK_LValue,
21572162
clang::SourceLocation()));
21582163
}
2159-
auto memberCall = clangSema.BuildCallToMemberFunction(
2164+
auto memberCall = clangSema.BuildCallExpr(
21602165
nullptr, memberExpr, clang::SourceLocation(), args,
21612166
clang::SourceLocation());
21622167
if (!memberCall.isUsable())

0 commit comments

Comments
 (0)