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-3920] compiler crashes with 3.1, worked with 3.0.2 #46505

Closed
swift-ci opened this issue Feb 10, 2017 · 4 comments
Closed

[SR-3920] compiler crashes with 3.1, worked with 3.0.2 #46505

swift-ci opened this issue Feb 10, 2017 · 4 comments

Comments

@swift-ci
Copy link
Collaborator

@swift-ci swift-ci commented Feb 10, 2017

Previous ID SR-3920
Radar rdar://problem/30477054
Original Reporter miodrag (JIRA User)
Type Bug
Status Closed
Resolution Done

Attachment: Download

Environment

macOS sierra, Xcode 8.2.1 with swift-3.1-DEVELOPMENT-SNAPSHOT-2017-02-07-a.xctoolchain

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 3.1Regression, SILGen
Assignee None
Priority Medium

md5: ed99c20cc6d7d25dba6cf76215538ddb

Issue Description:

running attached file, "swift crash.swift", results in a crash with "Apple Swift version 3.1-dev (LLVM a7c680da51, Clang 7c1383ec50, Swift f828572)"
"Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)" worked fine.
It does work with 3.1 if initializers are uncommented.

result:

SIL verification failed: upcast must cast to a superclass or an existential metatype: ToTy.isExactSuperclassOf(FromTy)
Verifying instruction:
     %4 = apply %3(%2) : $@convention(method) (@thick NSViewController.Type) -> @owned NSViewController, scope 0 // user: %5
->   %5 = upcast %4 : $NSViewController to $Content, scope 0 // user: %6
     store %5 to [init] %0 : $*Content, scope 0   // id: %6
In function:
sil_scope 1 {  parent @_TTWC5crash7ContentS_15ContentProtocolS_FS1_CfT_x : $@convention(witness_method) (@thick Content.Type) -> @out Content }

// protocol witness for ContentProtocol.init() -> A in conformance Content
sil hidden [transparent] [thunk] @_TTWC5crash7ContentS_15ContentProtocolS_FS1_CfT_x : $@convention(witness_method) (@thick Content.Type) -> @out Content {
// %0                                             // user: %6
// %1                                             // user: %2
bb0(%0 : $*Content, %1 : $@thick Content.Type):
  %2 = upcast %1 : $@thick Content.Type to $@thick NSViewController.Type, scope 1 // user: %4
  // function_ref NSViewController.__allocating_init() -> NSViewController
  %3 = function_ref @_TFCSo16NSViewControllerCfT_S_ : $@convention(method) (@thick NSViewController.Type) -> @owned NSViewController, scope 1 // user: %4
  %4 = apply %3(%2) : $@convention(method) (@thick NSViewController.Type) -> @owned NSViewController, scope 1 // user: %5
  %5 = upcast %4 : $NSViewController to $Content, scope 1 // user: %6
  store %5 to [init] %0 : $*Content, scope 1      // id: %6
  %7 = tuple (), scope 1                          // user: %8
  return %7 : $(), scope 1                        // id: %8
} // end sil function '_TTWC5crash7ContentS_15ContentProtocolS_FS1_CfT_x'

0  swift                    0x0000000106fda998 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x0000000106fd9bb6 llvm::sys::RunSignalHandlers() + 86
2  swift                    0x0000000106fdafe9 SignalHandler(int) + 361
3  libsystem_platform.dylib 0x00007fffdffd8bba _sigtramp + 26
4  libsystem_platform.dylib 0x00007fff5ba9f060 _sigtramp + 2074895552
5  libsystem_c.dylib        0x00007fffdfe5f420 abort + 129
6  swift                    0x0000000104c1f331 (anonymous namespace)::SILVerifier::_require(bool, llvm::Twine const&, std::__1::function<void ()> const&) + 497
7  swift                    0x0000000104c3bb4c swift::SILVisitor<(anonymous namespace)::SILVerifier, void>::visit(swift::ValueBase*) + 103724
8  swift                    0x0000000104c21123 (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) + 1347
9  swift                    0x0000000104c1c807 swift::SILFunction::verify(bool) const + 6711
10 swift                    0x0000000104c1e805 swift::SILModule::verify() const + 197
11 swift                    0x00000001047edfe1 swift::Lowering::SILGenModule::~SILGenModule() + 33
12 swift                    0x00000001047f92d8 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 1896
13 swift                    0x00000001047f93b6 swift::performSILGeneration(swift::ModuleDecl*, swift::SILOptions&, bool, bool) + 38
14 swift                    0x00000001041a5af7 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7495
15 swift                    0x0000000104162920 main + 3312
16 libdyld.dylib            0x00007fffdfdcb255 start + 1
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-3.1-DEVELOPMENT-SNAPSHOT-2017-02-07-a.xctoolchain/usr/bin/swift -frontend -interpret crash.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -color-diagnostics -module-name crash 
1.  While verifying SIL function @_TTWC5crash7ContentS_15ContentProtocolS_FS1_CfT_x for 'init' in module 'AppKit'
Abort trap: 6
@belkadan
Copy link
Contributor

@belkadan belkadan commented Feb 11, 2017

@swift-ci create

@jckarter
Copy link
Member

@jckarter jckarter commented Feb 14, 2017

From what I can tell, 3.0.2 has the same underlying problem—the type checker treats the reference to Animal.init(species:) as having type Animal -> ... -> Animal?, even though we're calling it on a Dog, and we expect the result of the ForceValueExpr to have type Dog, a coercion we can't do since it's going backwards from supertype to subtype. Perhaps this somehow manages to avoid enough internal inconsistency problems in release builds of the compiler not to crash.

@jckarter
Copy link
Member

@jckarter jckarter commented Feb 16, 2017

This should fix it:
Master: https://github.com/apple/swift/pull/7534/files
3.1: #7543

@swift-ci
Copy link
Collaborator Author

@swift-ci swift-ci commented Feb 25, 2017

Comment by Miodrag (JIRA)

Yes, it does work now

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants