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-6984] Calling .rawValue seg faults on release builds #49532

Open
swift-ci opened this issue Feb 12, 2018 · 6 comments
Open

[SR-6984] Calling .rawValue seg faults on release builds #49532

swift-ci opened this issue Feb 12, 2018 · 6 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-6984
Radar rdar://problem/37463182
Original Reporter plivesey (JIRA User)
Type Bug

Attachment: Download

Environment

Version 9.2 (9C40b)

Simulator or device (both reproduce the bug)

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

md5: 1385af2a973363f13a1ab0c99e9f213f

Issue Description:

If you have a simple enum which is RawRepresentable and call .rawValue on it, it crashes the compiler on release builds. The following code will crash the compiler, only if you have a RELEASE (optimized build).

// Must be in a separate file
enum AEnum: RawRepresentable {
    case a
    
    init?(rawValue: RawValue) {
        self = .a
    }
    
    var rawValue: String {
        return "a"
    }
}

// In a different file
let myEnum = AEnum.a.rawValue

To reproduce, opened the attach project and build for the simulator (it's already set to be a release build).

@belkadan
Copy link
Contributor

Might be about WMO, might be about actual optimization passes.

@swift-ci create

@belkadan
Copy link
Contributor

Hm, seems to be fixed in master, but also didn't reproduce on Swift 4.0.0. It's possible the reduced test case you've attached lost the actual problem.

@swift-ci
Copy link
Collaborator Author

Comment by Peter Livesey (JIRA)

🤦

It looks like the project I uploaded is missing a key line. You are right that this project does not reproduce the issue. You need to add:

let a = AEnum.a.rawValue

to viewDidLoad in ViewController

I'll update the project so it's easy for you to download and reproduce. Not sure how that line was missing from the uploaded project...

@swift-ci
Copy link
Collaborator Author

Comment by Peter Livesey (JIRA)

Uploaded the new attachment. Now, opening and building (Swift 4) reproduces the problem for me. Lmk if you still can't reproduce.

@belkadan
Copy link
Contributor

Looks like it no longer crashes on master, but it still doesn't work:

/Users/jrose/Downloads/LowercasedSegFault-2/LowercasedSegFault/File.swift:14:21: error: reference to invalid associated type 'RawValue' of type 'AEnum'
    init?(rawValue: RawValue) {
                    ^

You can work around this by writing String explicitly instead.

@swift-ci
Copy link
Collaborator Author

Comment by Peter Livesey (JIRA)

Ah...ok. That makes a bit more sense. I was confused why we hadn't seen this before.

@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
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

3 participants