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-8748] Inline init crashes in release configuration #51257

Closed
swift-ci opened this issue Sep 14, 2018 · 3 comments
Closed

[SR-8748] Inline init crashes in release configuration #51257

swift-ci opened this issue Sep 14, 2018 · 3 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 optimized only Flag: An issue whose reproduction requires optimized compilation run-time crash Bug → crash: Swift code crashed during execution

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-8748
Radar rdar://problem/44458427
Original Reporter grurenko (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 9.4.1 (9F2000)

Swift 4.1, Release configuration

iPhone X iOS 11.4

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

md5: eb8edd80a4f3d57f6f5cb37762d08d21

Issue Description:

What I do:

Build code below in Release configuration:

import UIKit

protocol Foo: class {
  func foo()
}

class Bar: Foo {
  func foo() {
    print("Success!")
  }
}

class Bazz: UIViewController {
  private let effectView = UIVisualEffectView(effect: UIBlurEffect(style: .dark))
  private let anyField = true
  unowned let bar: Foo
  
  init(_ foo: Foo) {
    bar = foo
    super.init(nibName: nil, bundle: nil)
  }
  
  required init?(coder aDecoder: NSCoder) {
    fatalError("")
  }
}

class Graph {
  let bar: Bar
  let bazz: Bazz
  let closure1: () -> Void
  let closure2: () -> Void
  
  init() {
    let bar = Bar()
    let bazz = Bazz(bar)
    closure1 = { [unowned bar] in
      bar.foo()
    }
    closure2 = { [unowned bar] in
      bar.foo()
    }
    self.bazz = bazz
    self.bar = bar
  }
}

func test() {
  let graph = Graph()
  graph.bazz.bar.foo()
}

What I expect:

Will print "Success!"

What I receive:

Fatal error: Attempted to read an unowned reference but object was already deallocated.

Possible workarounds:

1) Remove unowned from Bazz.bar property

2) Remove anyField property or chage type of effectView to UIView

3) Remove closure2 from Graph

@belkadan
Copy link
Contributor

@swift-ci create

@eeckstein
Copy link
Member

I could reproduce it with Xcode 9, but not anymore with Xcode 10. Seems to be fixed.
Can you please check with the latest Xcode 10 release?

@swift-ci
Copy link
Collaborator Author

Comment by Gleb Rurenko (JIRA)

It's not reproduced on Xcode 10.

@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 optimized only Flag: An issue whose reproduction requires optimized compilation run-time crash Bug → crash: Swift code crashed during execution
Projects
None yet
Development

No branches or pull requests

4 participants