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-1217] Wrong value after optimizations on Xcode 7.3 / Swift 2.2 #43825

Closed
swift-ci opened this issue Apr 13, 2016 · 7 comments
Closed

[SR-1217] Wrong value after optimizations on Xcode 7.3 / Swift 2.2 #43825

swift-ci opened this issue Apr 13, 2016 · 7 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself optimized only Flag: An issue whose reproduction requires optimized compilation

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-1217
Radar rdar://problem/25717872
Original Reporter fz (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

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

md5: af335a4cb7f50940b7c12be3e512affa

relates to:

  • SR-1216 Struct initializers defined in an extension are miscompiled with optimizations on.

Issue Description:

When having a framework containing a struct with 2 initializers (one from an extension) with a combination of a protocol such as:

public protocol ChargeAccount {
    var failed: Bool { get }
}

public struct CreditCard: ChargeAccount {
    public let failed: Bool

    public init() {
        self.failed = false
    }
}

extension CreditCard {

    public init(otherInit: Int) {
        self.failed = true
    }
}

public struct CurrentUser {
    public let chargeAccounts: [ChargeAccount]

    public init() {
        chargeAccounts = [CreditCard(otherInit: 1)]
    }
}

... and accessing this model from the main app as:

let user = CurrentUser()
print(user.chargeAccounts[0], user.chargeAccounts[0].failed)

the resulting value of `user.chargeAccounts[0].failed` is invalid (only when compiling for release mode, regardless of the optimization flags). This prints:

CreditCard(failed: true) false

Attached an example project.

@swift-ci
Copy link
Collaborator Author

Comment by Martin Conte Mac Donell (JIRA)

cc nadav (JIRA User)

@swiftix
Copy link
Mannequin

swiftix mannequin commented Apr 20, 2016

Hi Martin! Could you try to build your project with the Xcode 7.3.1 GM? We fixed a couple of bugs related to your bug report in this release.
Please let us know if the bug is still there.

@swift-ci
Copy link
Collaborator Author

swift-ci commented May 6, 2016

Comment by Martin Conte Mac Donell (JIRA)

@swiftix Seems to be fixed on 7.31. Thanks

@NachoSoto
Copy link
Contributor

We ran into a similar issue: yesterday I turned on -Owholemodule again (we've had it disabled for a while due to compiler bugs), and suddenly our test suite (running in release mode) has 3 failing tests. They do pass with -O, but not with whole module optimization.

It actually is a heisenbug: adding print statements to debug the problem (since LLDB is pretty useless in this case) makes tests pass.

I just verified that it's still an issue in 7.3.1.

@swiftix
Copy link
Mannequin

swiftix mannequin commented May 10, 2016

@NachoSoto Could you provide more information about your issue? To fix it, we'd need to reproduce it. I'd suggest you file a new issue for your problem. You can refer to this issue, if you think they are related. Thanks!

@swift-ci
Copy link
Collaborator Author

Comment by Andy Matuschak (JIRA)

Filed [SR-1502] (I work with Nacho).

@NachoSoto
Copy link
Contributor

Thanks andymatuschak (JIRA User) 😃

@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
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself optimized only Flag: An issue whose reproduction requires optimized compilation
Projects
None yet
Development

No branches or pull requests

2 participants