Skip to content

[SR-3853] Compiler segfault when compiling tests and using a class from another framework and extending a superclass of that class with a convenience init in another file #46438

@swift-ci

Description

@swift-ci
Previous ID SR-3853
Radar rdar://problem/30358828
Original Reporter ssheldon (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

macOS 10.12.3, Xcode 8.3 beta

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 3.1Regression, CompilerCrash
Assignee @belkadan
Priority Medium

md5: 712265ae61b936c756c7ed455a99853e

is duplicated by:

  • SR-3889 Swift compiler crashes with -O option

Issue Description:

Let's say you have a framework which defines a subclass of a UIKit view, like so:

public class ImageView: UIImageView { }

Now you're writing tests for your framework. You add a test utils extension to UIView:

extension UIView {
  convenience init(foo: String) {
    fatalError()
  }
}

Now, if you try to use the class from your framework in the tests, perhaps like this:

func foo(imageView: ImageView) { }

You'll receive a segfault when compiling your tests:

0  swift                    0x0000000104af3677 PrintStackTraceSignalHandler(void*) + 39
1  swift                    0x0000000104af2b26 SignalHandler(int) + 646
2  libsystem_platform.dylib 0x00007fffd110ebba _sigtramp + 26
3  libsystem_platform.dylib 0x0000000000000012 _sigtramp + 787420274
4  swift                    0x000000010246cbf6 swift::DeclContext::lookupQualified(swift::Type, swift::DeclName, swift::NLOptions, swift::LazyResolver*, llvm::SmallVectorImpl<swift::ValueDecl*>&) const + 3670
5  swift                    0x0000000102137633 (anonymous namespace)::SwiftDeclConverter::recordObjCOverride(swift::AbstractFunctionDecl*) + 387
6  swift                    0x0000000102136911 (anonymous namespace)::SwiftDeclConverter::importConstructor(clang::ObjCMethodDecl const*, swift::DeclContext*, bool, llvm::Optional<swift::CtorInitializerKind>, bool, swift::ObjCSelector, swift::importer::ImportedName, llvm::ArrayRef<clang::ParmVarDecl const*>, bool, bool&) + 8929
7  swift                    0x00000001021308df (anonymous namespace)::SwiftDeclConverter::importConstructor(clang::ObjCMethodDecl const*, swift::DeclContext*, bool, llvm::Optional<swift::CtorInitializerKind>, bool) + 767
8  swift                    0x000000010211adf9 (anonymous namespace)::SwiftDeclConverter::importObjCMethodDecl(clang::ObjCMethodDecl const*, swift::DeclContext*, bool) + 361
9  swift                    0x0000000102110fd9 clang::declvisitor::Base<clang::declvisitor::make_const_ptr, (anonymous namespace)::SwiftDeclConverter, swift::Decl*>::Visit(clang::Decl const*) + 1481
10 swift                    0x0000000102110234 swift::ClangImporter::Implementation::importDeclAndCacheImpl(clang::NamedDecl const*, swift::importer::ImportNameVersion, bool) + 532
11 swift                    0x000000010213be63 (anonymous namespace)::SwiftDeclConverter::importObjCMembers(clang::ObjCContainerDecl const*, swift::DeclContext*, llvm::SmallPtrSet<swift::Decl*, 4u>&, llvm::SmallVectorImpl<swift::Decl*>&) + 243
12 swift                    0x000000010213a80f swift::ClangImporter::Implementation::loadAllMembers(swift::Decl*, unsigned long long) + 447
13 swift                    0x0000000102427bfd swift::NominalTypeDecl::getMembers() const + 125
14 swift                    0x000000010246e00b swift::NominalTypeDecl::lookupDirect(swift::DeclName, bool) + 491
15 swift                    0x0000000102045485 swift::ModuleFile::getDecl(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 31781
16 swift                    0x0000000102046ac7 swift::ModuleFile::getDecl(llvm::PointerEmbeddedInt<unsigned int, 31>, llvm::Optional<swift::DeclContext*>) + 37479
17 swift                    0x0000000102053168 swift::ModuleFile::loadAllMembers(swift::Decl*, unsigned long long) + 600
18 swift                    0x0000000102427bfd swift::NominalTypeDecl::getMembers() const + 125
19 swift                    0x000000010246e00b swift::NominalTypeDecl::lookupDirect(swift::DeclName, bool) + 491
20 swift                    0x0000000101ce1159 swift::BottomUpFunctionOrder::DFS(swift::SILFunction*) + 1961
21 swift                    0x0000000101d8ebab swift::SILPassManager::runOneIteration() + 1243
22 swift                    0x0000000101b7656d swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 381
23 swift                    0x0000000101d94107 swift::runSILDiagnosticPasses(swift::SILModule&) + 1591
24 swift                    0x0000000101a14e28 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 42856
25 swift                    0x00000001019c44bc main + 9052
26 libdyld.dylib            0x00007fffd0f01255 start + 1
Stack dump:
1.  While loading members for 'ImageView' in module 'Baz'
2.  While deserializing 'init' (ConstructorDecl #&#8203;3)in 'Baz'
3.  While deserializing decl #&#8203;31 (XREF)in 'Baz'
4.  Cross-reference to module 'UIKit'
    ... UIImageView
    ... init
    ... with type (UIImageView.Type) -> (Optional<UIImage>) -> UIImageView
5.  /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.3.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIImageView.h:16:40: loading members for 'UIImageView'
6.  /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.3.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIImageView.h:18:1: importing 'UIImageView::initWithImage:'

This is a regression in Xcode 8.3 beta, this code compiles under Xcode 8.2. I've attached an example project to repro; just open the Baz project and attempt to test the Baz target by running BazTests.

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of software

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions