Skip to content

Commit e292f2f

Browse files
egorzhdancompnerd
authored andcommitted
[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 0ee89fc commit e292f2f

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
@@ -2149,14 +2149,19 @@ clang::CXXMethodDecl *SwiftDeclSynthesizer::synthesizeCXXForwardingMethod(
21492149
thisExpr = conv.get();
21502150
}
21512151

2152+
auto memberExprTy =
2153+
(method->isStatic() && method->getOverloadedOperator() ==
2154+
clang::OverloadedOperatorKind::OO_Call)
2155+
? method->getType()
2156+
: clangCtx.BoundMemberTy;
21522157
auto memberExpr = clangSema.BuildMemberExpr(
21532158
thisExpr, /*isArrow=*/true, clang::SourceLocation(),
21542159
clang::NestedNameSpecifierLoc(), clang::SourceLocation(),
21552160
const_cast<clang::CXXMethodDecl *>(method),
21562161
clang::DeclAccessPair::make(const_cast<clang::CXXMethodDecl *>(method),
21572162
clang::AS_public),
21582163
/*HadMultipleCandidates=*/false, method->getNameInfo(),
2159-
clangCtx.BoundMemberTy, clang::VK_PRValue, clang::OK_Ordinary);
2164+
memberExprTy, clang::VK_PRValue, clang::OK_Ordinary);
21602165
llvm::SmallVector<clang::Expr *, 4> args;
21612166
for (size_t i = 0; i < newMethod->getNumParams(); ++i) {
21622167
auto *param = newMethod->getParamDecl(i);
@@ -2167,7 +2172,7 @@ clang::CXXMethodDecl *SwiftDeclSynthesizer::synthesizeCXXForwardingMethod(
21672172
clangCtx, param, false, type, clang::ExprValueKind::VK_LValue,
21682173
clang::SourceLocation()));
21692174
}
2170-
auto memberCall = clangSema.BuildCallToMemberFunction(
2175+
auto memberCall = clangSema.BuildCallExpr(
21712176
nullptr, memberExpr, clang::SourceLocation(), args,
21722177
clang::SourceLocation());
21732178
if (!memberCall.isUsable())

0 commit comments

Comments
 (0)