Skip to content

[SILGen] Don't SILGen an @objc entry point for a deinit with no body #19472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ void SILGenModule::emitObjCAllocatorDestructor(ClassDecl *cd,
DestructorDecl *dd) {
// Emit the native deallocating destructor for -dealloc.
// Destructors are a necessary part of class metadata, so can't be delayed.
{
if (dd->hasBody()) {
SILDeclRef dealloc(dd, SILDeclRef::Kind::Deallocator);
SILFunction *f = getFunction(dealloc, ForDefinition);
preEmitFunction(dealloc, dd, f, dd);
Expand All @@ -916,7 +916,7 @@ void SILGenModule::emitObjCAllocatorDestructor(ClassDecl *cd,

// Emit the Objective-C -dealloc entry point if it has
// something to do beyond messaging the superclass's -dealloc.
if (dd->getBody()->getNumElements() != 0)
if (dd->hasBody() && dd->getBody()->getNumElements() != 0)
emitObjCDestructorThunk(dd);

// Emit the ivar initializer, if needed.
Expand Down
59 changes: 59 additions & 0 deletions test/ModuleInterface/ObjC.swiftinterface
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-module -o %t/ObjC.swiftmodule -O -enable-objc-interop %s
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-module -o %t/ObjC.swiftmodule -O -enable-objc-interop -enable-resilience %s

// FIXME: This test is self-contained, so it shouldn't require objc_interop
// (just -enable-objc-interop), but it's failing in Linux SILGen.
// https://bugs.swift.org/browse/SR-8877
// REQUIRES: objc_interop

import Foundation

public class SomeClass {
@objc init?(_: Any)
@objc func foo()
@objc var bar: Int { get set }
@objc subscript(_: Int) -> Int { get set }
@objc deinit
}

public class SomeClassInlinable {
@usableFromInline init()
@objc @inlinable convenience init?(_: Any) { self.init() }
@objc @inlinable func foo() {}
@objc var bar: Int {
@inlinable get { return 0 }
@inlinable set {}
}
@objc @inlinable subscript(_: Int) -> Int {
@inlinable get { return 0 }
@inlinable set {}
}
@objc @inlinable deinit {
print("bye")
}
}
public class SomeNSObject : NSObject {
@objc init?(_: Any)
@objc func foo()
@objc var bar: Int { get set }
@objc subscript(_: Int) -> Int { get set }
@objc deinit
}

public class SomeNSObjectInlinable : NSObject {
public override init()
@objc @inlinable convenience init?(_: Any) { self.init() }
@objc @inlinable func foo() {}
@objc var bar: Int {
@inlinable get { return 0 }
@inlinable set {}
}
@objc @inlinable subscript(_: Int) -> Int {
@inlinable get { return 0 }
@inlinable set {}
}
@objc @inlinable deinit {
print("bye")
}
}