Skip to content
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

[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

Closed
swift-ci opened this issue Feb 3, 2017 · 6 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Feb 3, 2017

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.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Feb 3, 2017

Comment by Steven Sheldon (JIRA)

Curiously, if you move the UIView extension into the same file where you're testing ImageView, the segfault stops.

@belkadan
Copy link
Contributor

belkadan commented Feb 3, 2017

Reproduced.

@belkadan
Copy link
Contributor

belkadan commented Feb 3, 2017

@swift-ci create

@belkadan
Copy link
Contributor

belkadan commented Feb 6, 2017

#7284

@belkadan
Copy link
Contributor

belkadan commented Feb 7, 2017

3.1 branch: #7288

@belkadan
Copy link
Contributor

belkadan commented Feb 7, 2017

Merged as 366b4bc. Note that it may take a while for this to get into an Xcode release, but if you'd like to test it sooner you can download a development snapshot from https://swift.org/download/#snapshots.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

3 participants