Skip to content

Commit ebe83a4

Browse files
committed
[cxx-interop] WA: skip virtual function import when symbolic import enabled
This is a simple work around to avoid importing virtual functions when symbolic imports are turned on. Test cases that were failing before this WA are in test/Interop/Cxx/symbolic-imports. Thanks to Alex Lorenz for providing this WA to me (@hyp).
1 parent 128064f commit ebe83a4

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

include/swift/ClangImporter/ClangImporter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,9 @@ class ClangImporter final : public ClangModuleLoader {
611611
/// Enable the symbolic import experimental feature for the given callback.
612612
void withSymbolicFeatureEnabled(llvm::function_ref<void(void)> callback);
613613

614+
/// Returns true when the symbolic import experimental feature is enabled.
615+
bool isSymbolicImportEnabled() const;
616+
614617
const clang::TypedefType *getTypeDefForCXXCFOptionsDefinition(
615618
const clang::Decl *candidateDecl) override;
616619

lib/ClangImporter/ClangImporter.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4789,6 +4789,12 @@ static clang::CXXMethodDecl *synthesizeCxxBaseMethod(
47894789
bool isVirtualCall = false) {
47904790
auto &clangCtx = impl.getClangASTContext();
47914791
auto &clangSema = impl.getClangSema();
4792+
// When emitting symbolic decls, the method might not have a concrete
4793+
// record type as this type.
4794+
if (impl.isSymbolicImportEnabled()
4795+
&& !method->getThisType()->getPointeeCXXRecordDecl()) {
4796+
return nullptr;
4797+
}
47924798

47934799
// Create a new method in the derived class that calls the base method.
47944800
clang::DeclarationName name = method->getNameInfo().getName();
@@ -7454,6 +7460,10 @@ void ClangImporter::withSymbolicFeatureEnabled(
74547460
oldImportSymbolicCXXDecls.get());
74557461
}
74567462

7463+
bool ClangImporter::isSymbolicImportEnabled() const {
7464+
return Impl.importSymbolicCXXDecls;
7465+
}
7466+
74577467
const clang::TypedefType *ClangImporter::getTypeDefForCXXCFOptionsDefinition(
74587468
const clang::Decl *candidateDecl) {
74597469

lib/ClangImporter/ImportDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3723,7 +3723,8 @@ namespace {
37233723
decl->getParent(), decl->getParent(), decl);
37243724

37253725
// call the __synthesizedVirtualCall_ C++ thunk from a Swift thunk
3726-
if (Decl *swiftThunk = VisitCXXMethodDecl(cxxThunk);
3726+
if (Decl *swiftThunk =
3727+
cxxThunk ? VisitCXXMethodDecl(cxxThunk) : nullptr;
37273728
isa_and_nonnull<FuncDecl>(swiftThunk)) {
37283729
// synthesize the body of the Swift method to call the swiftThunk
37293730
synthesizeForwardingThunkBody(cast<FuncDecl>(method),

0 commit comments

Comments
 (0)