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-10940] SILOptimizer crash when inlinable init of a derived class implicitly calls base class's implicit init #53331

Closed
swift-ci opened this issue Jun 16, 2019 · 2 comments
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

Previous ID SR-10940
Radar None
Original Reporter broadway_lamb (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

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

But also crashes in macOS.

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

md5: 6ecf784f300d9ba68661d2a3900c536f

Issue Description:

This code

public class C {

    @usableFromInline internal let base: Base

    @inlinable init() {
        base = Derived(bar: 1)
    }
}

@usableFromInline internal class Base {
    // uncomment this to prevent compiler crash
    // @inlinable init () {}
}

@usableFromInline internal final class Derived: Base {

    @inlinable init(bar: Int) {

        // uncomment this to prevent compiler crash
        // super.init()
    }
}

produces this crash:

SIL verification failed: function_ref inside fragile function cannot reference a private or hidden symbol: (SingleFunction && RefF->isExternalDeclaration()) || RefF->hasValidLinkageForFragileRef()
Verifying instruction:
->   // function_ref Base.init()
  %10 = function_ref @$s6output4BaseCACycfc : $@convention(method) (@owned Base) -> @owned Base // user: %11
     %11 = apply %10(%9) : $@convention(method) (@owned Base) -> @owned Base // user: %12
In function:
// Derived.init(bar:)
sil [serialized] @$s6output7DerivedC3barACSi_tcfc : $@convention(method) (Int, @owned Derived) -> @owned Derived {
// %0                                             // user: %5
// %1                                             // user: %6
bb0(%0 : @trivial $Int, %1 : @owned $Derived):
  %2 = alloc_box ${ var Derived }, let, name "self" // user: %3
  %3 = mark_uninitialized [derivedself] %2 : ${ var Derived } // users: %15, %4
  %4 = project_box %3 : ${ var Derived }, 0       // users: %14, %13, %8, %6
  debug_value %0 : $Int, let, name "bar", argno 1 // id: %5
  store %1 to [init] %4 : $*Derived               // id: %6
  br bb1                                          // id: %7
bb1:                                              // Preds: bb0
  %8 = load [take] %4 : $*Derived                 // user: %9
  %9 = upcast %8 : $Derived to $Base              // user: %11
  // function_ref Base.init()
  %10 = function_ref @$s6output4BaseCACycfc : $@convention(method) (@owned Base) -> @owned Base // user: %11
  %11 = apply %10(%9) : $@convention(method) (@owned Base) -> @owned Base // user: %12
  %12 = unchecked_ref_cast %11 : $Base to $Derived // user: %13
  store %12 to [init] %4 : $*Derived              // id: %13
  %14 = load [copy] %4 : $*Derived                // user: %16
  destroy_value %3 : ${ var Derived }             // id: %15
  return %14 : $Derived                           // id: %16
} // end sil function '$s6output7DerivedC3barACSi_tcfc'
Stack dump:
0.  Program arguments: /opt/compiler-explorer/swift-5.0/usr/bin/swift -frontend -S -primary-file <source> -target x86_64-unknown-linux-gnu -disable-objc-interop -g -enable-anonymous-context-mangled-names -Xllvm --x86-asm-syntax=intel -module-name output -o ./output.s 
1.  While silgen constructor initializer SIL function "@$s6output7DerivedC3barACSi_tcfc".
 for 'init(bar:)' (at <source>:17:16)
2.  While verifying SIL function "@$s6output7DerivedC3barACSi_tcfc".
 for 'init(bar:)' (at <source>:17:16)
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0x462b784]
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0x4629550]
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0x462b932]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x12890)[0x7f9622452890]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0xc7)[0x7f9620ad2e97]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x141)[0x7f9620ad4801]
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0x13a4c00]
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0x13d9e4a]
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0x13aa0d3]
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0x13a8156]
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0x13a01a1]
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0xe32eb7]
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0xe3bc4d]
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0xe33e13]
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0xeded67]
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0xedeba8]
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0xe3872c]
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0xe39637]
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0xe39cba]
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0x4e986a]
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0x4e6706]
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0x48da7e]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)[0x7f9620ab5b97]
/opt/compiler-explorer/swift-5.0/usr/bin/swift[0x48b8b9]
Compiler returned: 255

when compiled with -O -wmo flags

See: https://godbolt.org/z/Dpq9HF

As I've mentioned, the workaround is to add an explicit @inlinable/@usableFromInline initializer to the base class.

@belkadan
Copy link
Contributor

Oops. @slavapestov, which way should this go? It seems weird to inherit @inlinable.

@slavapestov
Copy link
Member

#25556

@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

4 participants