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-6662] Compiler crash: Basic blocks must end with a terminator in throwing init #49211

Closed
WFT opened this issue Dec 24, 2017 · 2 comments
Closed

Comments

@WFT
Copy link

@WFT WFT commented Dec 24, 2017

Previous ID SR-6662
Radar None
Original Reporter @WFT
Type Bug
Status Resolved
Resolution Duplicate
Environment

Ubuntu 16.04 (I tried three snapshots):

Swift version 4.0.3 (swift-4.0.3-RELEASE)
Target: x86_64-unknown-linux-gnu

Swift version 4.1-dev (LLVM 5d946db43c, Clang 1212e53405, Swift 810bc89)
Target: x86_64-unknown-linux-gnu

Swift version 4.1-dev (LLVM 5d946db43c, Clang 1212e53405, Swift 810bc89)
Target: x86_64-unknown-linux-gnu

macOS:

Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)
Target: x86_64-apple-macosx10.9

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

md5: 3e9625802894e8a388e0a08cdcc499b3

duplicates:

Issue Description:

The Swift compiler crashes when compiling the following code on Ubuntu, but not on macOS:

class TestCrash {
    init() throws { }
}

class HereComesTheCrash: TestCrash {
    override init() throws {
        fatalError()
    }    
}

but not if you add a `super.init()` call like so:

class TestCrash {
    init() throws { }
}

class HereComesTheCrash: TestCrash {
    override init() throws {
        try super.init()
        fatalError()
    }    
}

The fact that the subclass' init is overriding its superclass' init as well as the fact that they are throws seem to be important.

The full error is here:

> swift TestCrash.swift
SIL verification failed: Basic blocks must end with a terminator instruction: isa<TermInst>(BB.back())
In function:
// HereComesTheCrash.init()
sil hidden @_T09TestCrash012HereComesTheB0CACyKcfc : $@convention(method) (@owned HereComesTheCrash) -> (@owned HereComesTheCrash, @error Error) {
// %0                                             // user: %5
bb0(%0 : $HereComesTheCrash):
  %1 = alloc_box ${ var HereComesTheCrash }, let, name "self" // user: %2
  %2 = mark_uninitialized [derivedself] %1 : ${ var HereComesTheCrash } // users: %31, %24, %3
  %3 = project_box %2 : ${ var HereComesTheCrash }, 0 // users: %29, %28, %20, %5
  debug_value undef : $Error, var, name "$error", argno 1 // id: %4
  store %0 to [init] %3 : $*HereComesTheCrash     // id: %5
  // function_ref fatalError(_:file:line:)
  %6 = function_ref @_T0s10fatalErrors5NeverOSSyXK_s12StaticStringV4fileSu4linetF : $@convention(thin) (@owned @callee_owned () -> @owned String, StaticString, UInt) -> Never // user: %19
  // function_ref default argument 0 of fatalError(_:file:line:)
  %7 = function_ref @_T0s10fatalErrors5NeverOSSyXK_s12StaticStringV4fileSu4linetFfA_ : $@convention(thin) () -> @owned @callee_owned () -> @owned String // user: %8
  %8 = apply %7() : $@convention(thin) () -> @owned @callee_owned () -> @owned String // user: %19
  %9 = string_literal utf8 "TestCrash.swift"      // user: %14
  %10 = integer_literal $Builtin.Word, 15         // user: %14
  %11 = integer_literal $Builtin.Int1, -1         // user: %14
  %12 = metatype $@thin StaticString.Type         // user: %14
  // function_ref StaticString.init(_builtinStringLiteral:utf8CodeUnitCount:isASCII:)
  %13 = function_ref @_T0s12StaticStringVABBp08_builtinB7Literal_Bw17utf8CodeUnitCountBi1_7isASCIItcfC : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin StaticString.Type) -> StaticString // user: %14
  %14 = apply %13(%9, %10, %11, %12) : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin StaticString.Type) -> StaticString // user: %19
  // function_ref UInt.init(_builtinIntegerLiteral:)
  %15 = function_ref @_T0S2uBi2048_22_builtinIntegerLiteral_tcfC : $@convention(method) (Builtin.Int2048, @thin UInt.Type) -> UInt // user: %18
  %16 = metatype $@thin UInt.Type                 // user: %18
  %17 = integer_literal $Builtin.Int2048, 7       // user: %18
  %18 = apply %15(%17, %16) : $@convention(method) (Builtin.Int2048, @thin UInt.Type) -> UInt // user: %19
  %19 = apply %6(%8, %14, %18) : $@convention(thin) (@owned @callee_owned () -> @owned String, StaticString, UInt) -> Never
  %20 = load [take] %3 : $*HereComesTheCrash      // user: %21
  %21 = upcast %20 : $HereComesTheCrash to $TestCrash // user: %23
  // function_ref TestCrash.init()
  %22 = function_ref @_T09TestCrashAACAByKcfc : $@convention(method) (@owned TestCrash) -> (@owned TestCrash, @error Error) // user: %23
  try_apply %22(%21) : $@convention(method) (@owned TestCrash) -> (@owned TestCrash, @error Error), normal bb1, error bb2 // id: %23
  destroy_value %2 : ${ var HereComesTheCrash }   // id: %24
  return %29 : $HereComesTheCrash                 // id: %25

// %26                                            // user: %27
bb1(%26 : $TestCrash):                            // Preds: bb0
  %27 = unchecked_ref_cast %26 : $TestCrash to $HereComesTheCrash // user: %28
  store %27 to [init] %3 : $*HereComesTheCrash    // id: %28
  %29 = load [copy] %3 : $*HereComesTheCrash      // user: %25

// %30                                            // user: %32
bb2(%30 : $Error):                                // Preds: bb0
  destroy_value %2 : ${ var HereComesTheCrash }   // id: %31
  throw %30 : $Error                              // id: %32
} // end sil function '_T09TestCrash012HereComesTheB0CACyKcfc'

0  swift           0x0000000003ae91b8
1  swift           0x0000000003ae98f6
2  libpthread.so.0 0x00007f97016af390
3  libc.so.6       0x00007f96ffdee428 gsignal + 56
4  libc.so.6       0x00007f96ffdf002a abort + 362
5  swift           0x00000000010d59f7
6  swift           0x00000000010d30bc
7  swift           0x00000000010cfe5b
8  swift           0x0000000000bbcc67
9  swift           0x0000000000bc4aba
10 swift           0x0000000000bbde47
11 swift           0x0000000000c544ed
12 swift           0x0000000000c54258
13 swift           0x0000000000bc191b
14 swift           0x0000000000bc28c4
15 swift           0x0000000000bc2eff
16 swift           0x00000000004ad7d6
17 swift           0x00000000004aa52b
18 swift           0x0000000000465564
19 libc.so.6       0x00007f96ffdd9830 __libc_start_main + 240
20 swift           0x0000000000462e29
Stack dump:
0.    Program arguments: /swiftlang/usr/bin/swift -frontend -c -primary-file TestCrash.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -module-name TestCrash -o /tmp/TestCrash-bc091a.o
1.    While silgen constructor initializer SIL function "@_T09TestCrash012HereComesTheB0CACyKcfc".
 for 'init()' at TestCrash.swift:6:14
<unknown>:0: error: unable to execute command: Aborted
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)
@WFT
Copy link
Author

@WFT WFT commented Dec 24, 2017

Seems possibly related to SR-5974, but I really wasn't sure so I filed a new bug.

@belkadan
Copy link
Contributor

@belkadan belkadan commented Jan 2, 2018

It's failing for me with a +Asserts compiler on macOS as well, so I think the difference is just whether asserts are on. That means it's very likely the same thing after all. Thanks!

@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

2 participants