Skip to content

Commit

Permalink
[Serialization] Force destructor creation for imported class
Browse files Browse the repository at this point in the history
Swift class deinit decl can be implicitly synthesized when emitting
swiftmodule, so swiftmodule always have deinit decl. So resolution of
x-refs to deinit of swift class always success.
But when x-refs points deinit of clang imported class, it always failed
because clang importer doesn't force to synthesize deinit before looking
up.

x-refs to deinit decl appears in only deinit of its subclasses, so it's
serialized only when deinit have body. And deinit has body only on SIB
because deinit is always non-inlinable. It means that this missing of
deinit creation can be problem only on SIB

This commit changes to force to synthesize class deinit
decl before looking up members.
  • Loading branch information
kateinoigakukun committed Aug 13, 2020
1 parent 96587bc commit 878efac
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/Serialization/Deserialization.cpp
Expand Up @@ -1611,6 +1611,14 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) {
getXRefDeclNameForError());
}

if (memberName.getKind() == DeclBaseName::Kind::Destructor) {
assert(isa<ClassDecl>(nominal));
// Force creation of an implicit destructor
auto CD = dyn_cast<ClassDecl>(nominal);
values.push_back(CD->getDestructor());
break;
}

if (!privateDiscriminator.empty()) {
ModuleDecl *searchModule = M;
if (!searchModule)
Expand Down
4 changes: 4 additions & 0 deletions test/Serialization/Inputs/objc-xref/module.modulemap
@@ -0,0 +1,4 @@
module ObjCXRef {
header "objc_xref.h"
export *
}
2 changes: 2 additions & 0 deletions test/Serialization/Inputs/objc-xref/objc_xref.h
@@ -0,0 +1,2 @@
@interface MyObject
@end
9 changes: 9 additions & 0 deletions test/Serialization/xref-deinit.swift
@@ -0,0 +1,9 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-sib %s -o %t/xref-deinit.sib -I%t -I %S/Inputs/objc-xref
// RUN: %target-swift-frontend -emit-sil %t/xref-deinit.sib -I%t -I %S/Inputs/objc-xref

// REQUIRES: objc_interop

import ObjCXRef

public class Object: MyObject {}

0 comments on commit 878efac

Please sign in to comment.