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-2512] Switch case statement over integer value used to return enum cases leads to compiler crash, if optimization is enabled. #45117

Closed
swift-ci opened this issue Aug 28, 2016 · 1 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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-2512
Radar rdar://problem/28057990
Original Reporter palle (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Operating System: Mac OS X 10.11.6 (15G31),
Xcode Version 8.0 beta 6 (8S201h),
Swift version 3.0 (swiftlang-800.0.43.6 clang-800.0.38)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, OptimizedOnly
Assignee shajrawi (JIRA)
Priority Medium

md5: 7da33622778ac949894c52edd31db090

Issue Description:

When using a switch case statement over an integer value to return values of an enum, the compiler crashes, if two cases have the same condition and optimization is enabled.

The issue was observed with the following code example:

public enum DemoEnum {
    case firstCase
    case secondCase
    
    public static func performSwitch(with value: Int) -> DemoEnum {
        switch value {
        case 0:
            return DemoEnum.firstCase
        case 0:
            return DemoEnum.firstCase
        default:
            return DemoEnum.secondCase
        }
    }
}

The issue was observed, if the switch was performed over a integer value (unsigned and signed; 8, 16, 32 and 64 bit), but not with other values (String, Float, etc.)
The issue was also observed with RawRepresentable enums.
When using other return types (Strings, OptionSet values, Integer values, Enums with associated values), this issue was not reproducible.

The compiler was invoked with the following command:

swiftc -O ./Demo.swift

where Demo.swift was the file containing only the above swift code.

The compiler crashed with the warning

Duplicate integer as switch case
  switch i64 %0, label %4 [
    i64 0, label %2
    i64 0, label %3
  ]
i64 0
LLVM ERROR: Broken function found, compilation aborted!

In Xcode, this error was not visible and the compilation just failed (Error: swiftc failed with exit code 1).

@swift-ci
Copy link
Collaborator Author

Comment by Joe Shajrawi (JIRA)

resolved by the following commit 2fc6ae3

@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
Projects
None yet
Development

No branches or pull requests

2 participants